Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Smooth Rotation stop and start

Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
07-26-2006 21:34
here is somthing I was messing with today. a little smooth rotation sript. Although it does not stop turnning sometimes. One client will see it turning while the other won't. No clue on that one. Does not use tons of SetRots or Physics. So it is real easy on the servers.

CODE
rotation start_rot;
rotation stop_rot;
float lag = 0.2;
vector rot_axis;
float time_start;
float rate;
integer axis;
integer X = 1;
integer Y = 2;
integer Z = 3;

integer run = 1;

StartRotation(integer laxis, float lrate)
{
llResetTime();
start_rot = llGetLocalRot();
axis = laxis;
rate = lrate;
rate = (rate * DEG_TO_RAD);
if (axis == X) rot_axis = llVecNorm(llRot2Fwd (start_rot));
if (axis == Y) rot_axis = llVecNorm(llRot2Left (start_rot));
if (axis == Z) rot_axis = llVecNorm(llRot2Up (start_rot));
llSleep(0.3); //added to stop jitter on startup. odd?
time_start = llGetTime();
llTargetOmega(rot_axis, rate , 1.0);
}

StopRotation()
{
float angle = (rate * (llGetTime() - time_start)) + (rate * lag);
if (axis == X) stop_rot = llEuler2Rot(<angle, 0, 0>) * start_rot;
if (axis == Y) stop_rot = llEuler2Rot(<0, angle, 0>) * start_rot;
if (axis == Z) stop_rot = llEuler2Rot(<0, 0, angle>) * start_rot;
llSetLocalRot(stop_rot);
llTargetOmega(<1,0,0>, 0, 1);
}
default
{
state_entry()
{
stop_rot = llGetLocalRot();
}
touch_start(integer total_number)
{
if (run == 1)
{
StartRotation(X, 45.0);
run = 2;
}
else
{
StopRotation();
run = 1;
}
}
}


EDIT: had wrong values for Y ans Z
Archanox Underthorn
Registered User
Join date: 20 May 2003
Posts: 168
07-27-2006 19:04
I've noticed this with llTargetOmega as well, I've also noticed that a llSetPos or llSetRot call will cause the object to stop spinning if it gets stuck like this. So I would suggest if you have the time in your script, using one of those, moving the object a little and then moving it back.

Edit: Actually, I havent tried a 360 degree rotation, might wanna see if that works too.
_____________________
Archatek

Home to some of the highest quality katanas and other blades available in SL. Co-creator of the Samurai Island Combat System, one of the best melee combat systems available, come check it out!

___________________