Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Moving a prim relative to start position and rotation..

Talwyn Mills
Registered User
Join date: 8 May 2007
Posts: 51
07-05-2007 07:47
Hi All,

The is probably pretty simple, but I can\'t work out the maths or find anything that helps me out, so I\'m hoping someone here will help me.

I have a prim with an arbitrary rotation (static, its note a rotating prim) in all three axis and I want to move that prim a specific distance along one of the local axis. The distance and axis is selected at run time although the distance is always under 10 meters and the movement is always along only one of the prim local (not world) axis.

Can anyone help me out here?

Many Thanks

Talwyn.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-05-2007 08:18
If the translation offset is expressed in a vector (e.g., <5.0, 0.0, 0.0> to move +5.0m on the prim's local X axis), then llSetPos(llGetPos() + (offsetVector*llGetRot()) should work. (If the prim being moved is a child in a linkset, then you have to decide if you're translating on object-local (root) or (child) prim-local axes.)
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
07-05-2007 10:32
To find a position some distance along a given axis, You can simply make a vector with the desired axis set to 1.0 and the others 0.0, and multiply the vector by the distance.
Now you have a relative offset, which you can then rotate by your current rotation and add to your current position, here's a working example:

CODE


vector x_axis = <1.0, 0.0, 0.0>;
vector y_axis = <0.0, 1.0, 0.0>;
vector z_axis = <0.0, 0.0, 1.0>;

// assumes distance is under 10m
move_relative(vector direction, float distance)
{
vector offset_vec = llVecNorm(direction) * distance;

llSetPos(llGetPos() + (offset_vec * llGetRot()));
}


default
{
touch_start(integer total_number)
{
move_relative(x_axis + y_axis, 1.5);
}
}


Note: llVecNorm() allows you to add these vectors together and then move the specified distance along that combined vector (this example moves diagonally along x/y)
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Also see...
07-05-2007 10:36
Search these forums for "rotation" and "quaternion". Your question has been asked many times (by me, for example) and answered many times.

Search is your friend...

The reason Qie's answer works...

<5,1,2> is a vector relative to your prim. 5 meters in front (x), 1 meter to the left (y), and 2 meters up (z).

If you multiply a relative vector by the prim rotation, it gives you the same vector, only relative to the sim.

<5,1,2> * llGetRot()

llGetPos() is the position of your prim relative to the sim. So add those

llGetPos() + <5,1,2>*llGetRot()

and you get the new location relative to the sim.
Talwyn Mills
Registered User
Join date: 8 May 2007
Posts: 51
07-05-2007 16:47
Simple when you know how I see.

Thanks to everyone who responded, I'll try out your answers shortly.

And to Lee Ponzu, thanks for the explanation of why it works, quaternion is a new term to me but I will search more carefully next time.

Thanks