Aller au contenu

Photo

How can you set a Z axis for CreateObject?


  • Veuillez vous connecter pour répondre
19 réponses à ce sujet

#1
NewYears1978

NewYears1978
  • Members
  • 894 messages
When using createobject to place things in the world..you put the X, Y, Z but it seems as though Z is ignored...and the item is always placed at ground level.

I am trying for learning purposes to stack two crates but instead it just overlaps them.

Anyone have a workaround or can you not do this with CreateObject and can only do it with a new created area?

#2
NewYears1978

NewYears1978
  • Members
  • 894 messages
Wonders why every one of my toolset questions gets ignored basically..not even viewed! Would think simple questions would be able to be answered..at least by the Toolset team... can't be a hard question.. :\\

#3
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
Have you tried using SetPosition?

#4
Ranlas

Ranlas
  • Members
  • 96 messages
I don't think the forum is logging views at the moment. All of the more recent threads seems to have 0 views, then if they have replies.



My guess is also to use SetPosition(...) after you spawn the object.

#5
NewYears1978

NewYears1978
  • Members
  • 894 messages

Axe_Murderer wrote...

Have you tried using SetPosition?


Can you elaborate on this.? I am not a modder..or scripting by any means..I am doing tutorials and trying to learn that way.

I currently use Vector locations and CreateObject which has a Z setting in it..but the game seems to ignore the Z setting..I can put 500.0 there or pu 0 and it always sits on the ground.


Can't find any info on use for SetPosition...is there a GOOD toolset resource that actually has good info in it?  I can never find anything..which is why I use tutorials for learning instead..

Modifié par NewYears1978, 19 novembre 2009 - 08:34 .


#6
Languard

Languard
  • Members
  • 126 messages
This code snippet is take from here: social.bioware.com/wiki/datoolset/index.php/How-tos#Insert_content_into_an_existing_area

void main()
{
//Check whether we've added Joblo already.
if (WR_GetPlotFlag("joblos_quest", JOBLO_ADDED_TO_TOWN) == FALSE)
{
object oTown = GetObjectByTag("lot100ar_lothering"); //An area's tag is the same as its resource name
vector vJobloLocation = Vector(126.745f,120.724f,0.460568f); // See below for how to get these coordinates

CreateObject(
OBJECT_TYPE_CREATURE,
R"joblo.utc",
Location(oTown, vJobloLocation, 180.0f) //See below for how to get the value for orientation
)

WR_SetPlotFlag("joblos_quest", JOBLO_ADDED_TO_TOWN, TRUE);
}
}

Meh, I need to learn how to post code in this forum.  Anways, it shows an example of creating an object and setting a Z value.

#7
NewYears1978

NewYears1978
  • Members
  • 894 messages
Hm, that is very similar to what I am already using...only slightly different.

            object oArea = GetObjectByTag("cam100ar_camp_plains");

            location lCrate1Location = Location(oArea, Vector(186.0, 118.0, 0.0), -6.120553970);
            CreateObject(OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", lCrate1Location);


Here is the snippet of my code...I will try to compare and see if there is a difference.

Notice in my lCrate1Location..there is a value for X, Y, Z and orientation.  All work but Z is ignored (which is why I have 0 for the Z)

Edit--So upon comparing, if I change to this, it should work:

object oArea = GetObjectByTag("cam100ar_camp_plains");

vector vCrate1Location = Vector(186.0, 118.0, 0.0);
CreateObject(OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", Location(oArea, vCrate1Location,  -6.120553970)


Modifié par NewYears1978, 19 novembre 2009 - 08:51 .


#8
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages

NewYears1978 wrote...

Axe_Murderer wrote...
Have you tried using SetPosition?


Can you elaborate on this.? I am not a modder..or scripting by any means..I am doing tutorials and trying to learn that way.

I currently use Vector locations and CreateObject which has a Z setting in it..but the game seems to ignore the Z setting..I can put 500.0 there or pu 0 and it always sits on the ground.

Can't find any info on use for SetPosition...is there a GOOD toolset resource that actually has good info in it?  I can never find anything..which is why I use tutorials for learning instead..

It would go something like:
[dascript]
SetPosition( CreateObject( ... ), Vector( x, y, z ), FALSE );
[/dascript]
or, if you like using lots of variables:
[dascript]
float x = 186.0;
float y = 118.0;
float z = 0.0;
vector vCratePosition = Vector( x, y, z );
object oCrate = CreateObject( ... );
SetPosition( oCrate, vCratePosition, FALSE );
[/dascript]

Modifié par Axe_Murderer, 19 novembre 2009 - 08:55 .


#9
Jassper

Jassper
  • Members
  • 571 messages
CreatObject doesn't allow for a specific z, just a location. I am betting that it ignores the z and is only concerned with the x,y. Which is probably why you should use SetPosition() which does allow for a specified vector.

Would be worth the try.

#10
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
I suspect the problem is that CreateObject assumes the location you give it is safe. If it isn't, then it automatically makes it safe, which in the case of a placeable positioned in the air, causes gravity to pull it down to the ground. SetPosition allows you to specifically say "I want to put this in an unsafe location".


#11
NewYears1978

NewYears1978
  • Members
  • 894 messages
So If I use SetLocation I can do away with the location variables altogether? (lCrateLocation = ) part..

#12
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
No I doubt that. The create function will still need a valid location to put the thing, it will just adjust it so the object sits on the ground. So following the create with a SetPosition may allow you to change its z coordinate. You ought to use the same vector for both the location and the SetPosition however.

Modifié par Axe_Murderer, 19 novembre 2009 - 08:59 .


#13
NewYears1978

NewYears1978
  • Members
  • 894 messages
Okay I tried the first person suggestion



object oArea = GetObjectByTag("cam100ar_camp_plains");



vector vCrate1Location = Vector(186.0, 118.0, 5.0);

CreateObject(OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", Location(oArea, vCrate1Location, -6.120553970)



And basically, it just did the same thing as what I had (still ignoring the Z value)



So I will try Setlocation now..if I can figure it out..not quite sure how to do it..


#14
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
[dascript]
object   oArea                 = GetObjectByTag( "cam100ar_camp_plains" );
vector   vCrate1Position = Vector( 186.0, 118.0, 5.0 );
location lCrate1Location = Location( oArea, vCrate1Position, -6.120553970 );
object   oCrate               = CreateObject( OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", lCrate1Location );
SetPosition( oCrate, vCrate1Position, FALSE );
[/dascript]

Modifié par Axe_Murderer, 19 novembre 2009 - 09:32 .


#15
NewYears1978

NewYears1978
  • Members
  • 894 messages
Okay, I tried this and it didn't work.  So either setposition doesn't work either, OR I did this wrong (most likely)

CreateObject(OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", lCrate3Location);
SetPosition( CreateObject(OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", lCrate3Location), Vector(184.955,117.615,100.0), FALSE);


Edit:
I saw your above post after I posted this, I was trying to do it without all the variables as you mentioned...

Modifié par NewYears1978, 19 novembre 2009 - 09:34 .


#16
NewYears1978

NewYears1978
  • Members
  • 894 messages

Axe_Murderer wrote...

[dascript]
object   oArea                 = GetObjectByTag( "cam100ar_camp_plains" );
vector   vCrate1Position = Vector( 186.0, 118.0, 5.0 );
location lCrate1Location = Location( oArea, vCrate1Position, -6.120553970 );
object   oCrate               = CreateObject( OBJECT_TYPE_PLACEABLE, R"genip_crate_wood_large.utp", lCrate1Location );
SetPosition( oCrate, vCrate1Position, FALSE );
[/dascript]


This worked, thanks a million :)

#17
Sevenar

Sevenar
  • Members
  • 28 messages
I seem to recall there's a toggle in the area editors toolbars that forces all objects to snap to the walkable surface or something. Perhaps there's a flag for that you could turn off?



(not a modder, obviously)

#18
indio

indio
  • Members
  • 204 messages
Axe strikes again. If someone knows how to add to the wiki, this script would make a good entry.

#19
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
Here is a custom function that may come in handy for doing this more easily down the road:
[dascript]
object CreateObjectIn3DSpace( int nObjectType, resource rTemplate, location lLoc, string sOverrideScript = "",
                                                     int bSpawnActive = TRUE, int bNoPermDeath = FALSE )
{ object oNewObject = CreateObject( nObjectType, rTemplate, lLoc, sOverrideScript, bSpawnActive, bNoPermDeath );
   if( !IsObjectValid( oNewObject ) ) return OBJECT_INVALID;
  
   SetPosition( oNewObject, GetPositionFromLocation( lLoc), FALSE );
   return oNewObject;
}
[/dascript]

Modifié par Axe_Murderer, 19 novembre 2009 - 11:48 .


#20
NewYears1978

NewYears1978
  • Members
  • 894 messages
I had another question about this, how can you set orientation?



Currently it uses only the angle...how can you use the 3 coord orientation?