Author Topic: [SOLVED] Adding to a getTransform coord  (Read 988 times)

I know how to get and set transform, but I have honestly no clue how to add to this coords. Let's say I wanted to push the coord forward 10 blocks on one coord, how do I go about this?
« Last Edit: November 08, 2014, 05:17:50 PM by superdupercoolguy »


that's great, but what I'm asking is how do I add to one of those values, the coords themselves are 1 string containing 7 numbers.

%transform = %obj.getTransform(); //Let's say this is "0 1 2 3 4 5 6"

A Transform value has two components: a position and a rotation. The first three numbers indicate the position, and the last four are the rotation.

We only care about the position in this case, so when you do getTransform(), you probably want to single those out (the vector functions likely don't care but we'll do this for the sake of cleanliness)

%pos = getWords(%transform, 0, 2); //Does what it says; gets words 0-2 from %transform. %pos will be "0 1 2"

This is a Vector3f value. If you want to manipulate it effectively, you'll almost always want to use the host of vector functions available. The one we want here is VectorAdd. Some other common ones: VectorSub(%vecA, %vecB), VectorScale(%vec, %scale), VectorDist(%vecA, %vecB), VectorLen(%vec), VectorNormalize(%vec)

%new = VectorAdd(%pos, "X Y Z");

This will add the two provided vectors together. For your purposes, it may also be important to note that one stud = 0.5 Torque units and one plate = 0.2 Torque units. Take this into consideration when making your code.

%transform = %obj.getTransform(); //Let's say this is "0 1 2 3 4 5 6"
%pos = getWords(%transform, 0, 2);

There is a default getPosition function

There is a default getPosition function
This is also true. I didn't think about that since he asked specifically about transforms, but if you don't need the rotation, you should use getPosition instead.

Thanks for the help. I do care about rotations, so I will use transform.

You don't need to use transform unless you want to change the rotation
If you just change transform it'll keep the current rotation

well in that case, having transform is less useful.