Hard time find docs for "Vectors
by Steve Vall · in Torque Game Engine · 10/11/2005 (11:48 am) · 9 replies
Where can I find a detailed description on how to manipulate Vectors in scripts ? For example, if I get coordinates this way :
%Pos = $playerActor.getPosition();
How can I extract the X value from the %Pos ? How can I increment one of the two values ?
Thanks !
%Pos = $playerActor.getPosition();
How can I extract the X value from the %Pos ? How can I increment one of the two values ?
Thanks !
#2
you can also grab multiple values using getwords() function. if you wanted to obtain the x and y value separated by a space, you could do getwords(%Pos, 0,1).
edit: looks like kevin beat me to it. also, to answer your second question, changing the %pos variable wont have any effect on the object. the only way you can manipulate transform properties is using %obj.settransform(). so you would have to obtain the %Pos variable, change it, than call settransform using the result.
10/11/2005 (12:00 pm)
You use getword(%Pos,0) to get the first field, getword(%Pos,1) to get the second field, and getword(%Pos,2) to get the last field of a string separated by spaces. get used to the getword() function, youll be using it alot. you can also grab multiple values using getwords() function. if you wanted to obtain the x and y value separated by a space, you could do getwords(%Pos, 0,1).
edit: looks like kevin beat me to it. also, to answer your second question, changing the %pos variable wont have any effect on the object. the only way you can manipulate transform properties is using %obj.settransform(). so you would have to obtain the %Pos variable, change it, than call settransform using the result.
#3
And then, once I changed my individual values, I just rebuild the Vector using the SPC keyword, right?
10/11/2005 (12:03 pm)
Thanks you guys, that was fast.And then, once I changed my individual values, I just rebuild the Vector using the SPC keyword, right?
#4
so do:
%Pos = $playerActor.getTransform();
grab the x value, change it, replace the old x in %Pos with the new x value, then call
$playerActor.setTransform(%Pos);
or something equivalent to this.
yea i know its alot of work just to move something. I would suggest writing a small function which displaces an object so you can just call it when you want to move something.
10/11/2005 (12:44 pm)
Yes. however, if you plan to actually manipulate the object, you need to use setTransform() as I mentioned earlier. in order to use this function you also need to specify the rotation vector. so you need to get that too. the best thing to do is to use getTransform() instead of getPosition(). getTransform() gives you the position vector as well as the rotation. so do:
%Pos = $playerActor.getTransform();
grab the x value, change it, replace the old x in %Pos with the new x value, then call
$playerActor.setTransform(%Pos);
or something equivalent to this.
yea i know its alot of work just to move something. I would suggest writing a small function which displaces an object so you can just call it when you want to move something.
#5
10/11/2005 (1:04 pm)
Sean: Do you know the difference, if any, between getWord() and getField()?
#6
10/11/2005 (1:15 pm)
No. ive wondered that myself. maybe getfield involves a string separated by commas?? does anyone else know?
#7
One last question : what is the gain with this method? It seems to me that it's contrived for no real gains. Is it only to fix the lack of structs support in the Torque Script?
10/11/2005 (1:53 pm)
Thanks for the tips. One last question : what is the gain with this method? It seems to me that it's contrived for no real gains. Is it only to fix the lack of structs support in the Torque Script?
#8
not sure what u mean by it being contrived. it is rather low-level and it would be nice to have a function specifically for moving x units in x direction or rotating x units about an arbitrary axis. one of the first things I did when i started was to write a small displace(x,y,z) function at the netobject level and I've never had to deal with it again. achieving custom rotation is the really tricky party.
10/11/2005 (2:18 pm)
I believe you can use the ScriptObject object to create your own structs. a ScriptObject is the only object which has almost no properties and is used mainly to create custom objects. the syntax may not be exactly the same as using C, but it can be used to achieve the same end.not sure what u mean by it being contrived. it is rather low-level and it would be nice to have a function specifically for moving x units in x direction or rotating x units about an arbitrary axis. one of the first things I did when i started was to write a small displace(x,y,z) function at the netobject level and I've never had to deal with it again. achieving custom rotation is the really tricky party.
#9
This occasional need to "contrive" formatted strings is a trade off for the more loose structure of the scripting language, which in the long run is a big benefit for non-programmer style level designers, artists, etc. that use scripting as their means of implementation.
10/11/2005 (6:33 pm)
@Steve: As an FYI, most script based languages are string based, and it's one of the actual benefits of a type-less language to only have strings as your basis for operations. Yes, in some cases it makes you push and pull values from a formatted string, but on the whole it gives you a lot more flexibility/freedom on the script side.This occasional need to "contrive" formatted strings is a trade off for the more loose structure of the scripting language, which in the long run is a big benefit for non-programmer style level designers, artists, etc. that use scripting as their means of implementation.
Torque Owner Kevin Johnson
The position returned is a string delimited with spaces.