Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotating script

Franck Messmer
Registered User
Join date: 31 Mar 2007
Posts: 4
04-09-2007 08:18
Hi,
I think this subject had be explained many many times but I do not find a simple example of rotating script amoung various threads.

I want to rorate a multi-prims object in this way :
Go
Turn right (rotation on the right)
Go
Turn right (rotation on the right)
Go
Turn right (rotation on the right)
Go
Turn right (rotation on the right, then back to the starting point)

My object go back to the starting point but his orientation is completly absurd !
Could I have your help to find the mistake ?

CODE

vector startPoint;
vector currentPoint;
float speed = 0.1;

integer direction; //1 = front, 2 = right, 3 = left, 4 = back

default
{
state_entry()
{
//No use for instance
startPoint = llGetPos();
}

touch_start(integer total_number)
{
rotation Rotation = llEuler2Rot(<0,0,PI/4>);

for (direction = 1; direction < 5; direction++)
{
currentPoint = llGetPos();
integer i;
for(i = 0; i < 5; i++ )
{
if (direction == 1)
{
currentPoint = currentPoint + < i*speed, 0, 0>;
}
if (direction == 2)
{
currentPoint = currentPoint + < 0, -i*speed, 0>;
}
if (direction == 3)
{
currentPoint = currentPoint + < -i*speed, 0, 0>;
}
if (direction == 4)
{
currentPoint = currentPoint + < 0, i*speed, 0>;
}
llSetPos(currentPoint);
}
Rotation = Rotation * llGetRot();
llSetRot(Rotation);
}
}
}
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
04-09-2007 17:13
instead of:
CODE

Rotation = Rotation * llGetRot();
llSetRot (Rotation);


try:
CODE

llSetRot(llGetRot() * Rotation);

Rotation should remain at 90 degrees. Your prim will keep the current rotation.
Franck Messmer
Registered User
Join date: 31 Mar 2007
Posts: 4
04-10-2007 22:52
Yes, it is...
I had quite difficulties with this concept that rotation must to be without temp variable to keep current rotation.
However, maybee I'm not saw it but, I find amazing that nobody has proposed a set of usefull functions (excepts in tutorials but there are not globlal examples).

Then, this is functions that I propose (approvals tests) :

CODE

rotateX(integer degree)
{
llSetRot(llEuler2Rot(< 0, degree * DEG_TO_RAD, 0 >) * llGetRot());
}
rotateY(integer degree)
{
llSetRot(llEuler2Rot(< degree * DEG_TO_RAD, 0, 0 >) * llGetRot());
}
rotateZ(integer degree)
{
llSetRot(llEuler2Rot(< 0, 0, degree * DEG_TO_RAD >) * llGetRot());
}
moveX(integer distance)
{
llSetPos(llGetPos() + < distance, 0, 0 >);
}
moveY(integer distance)
{
llSetPos(llGetPos() + < 0, distance, 0 >);
}
moveZ(integer distance)
{
llSetPos(llGetPos() + < 0, 0, distance >);
}
Quinn Epsilon
Registered User
Join date: 13 Sep 2005
Posts: 3
08-13-2007 08:13
This is great!
I have one question.
How would these look if you wanted to get the rotation of the object your in?
Say on a timer so it always knows it's own rotation in degree?

I need to detect this to make effects depending which way the object is facing or is tilted.
Jotheph Nemeth
Registered User
Join date: 9 Aug 2007
Posts: 142
08-13-2007 11:03
PI/4 is only 45 degrees.

A circle is TWO_PI, 180 degrees is PI, and 90 degrees is PI/2.

I'm also a little leery of the code here:
Rotation = Rotation * llGetRot();
llSetRot(Rotation);

The quaterian calculations still confuse me some, so I don't know if this works or not. If there's any question, I'd try it with euler first, verify it works ok, and then try it without euler.