Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to make a "smooth" rotation?

Joakim Yakan
Fast learner
Join date: 2 Oct 2006
Posts: 31
10-19-2006 13:48
Hello!

Could someone please tell me how to make a smooth rotating object?
I've created a loop that repeats the llSetRot( newRotation );. I think this function got some delay. Is it another way to rotate an object?

CODE

default
{
state_entry()
{
vector startPoint = llGetPos();

rotation Y_1 = llEuler2Rot( < 0, 0, 20 * DEG_TO_RAD > );

integer x = 1;
integer a = 0;

while(x != a)
{
rotation newRotation = llGetRot() * Y_1;
llSetRot( newRotation );
}
}
}
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-19-2006 14:02
llTargetOmega
Joakim Yakan
Fast learner
Join date: 2 Oct 2006
Posts: 31
10-19-2006 14:22
Thanks a lot!
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
use a timer
10-19-2006 14:29
i might be way off base here, I'm still learning...

But, the problem is that your script only rotates as fast as the sim runs.

i think you need to start a timer, say every .1 seconds. When you receive the timer event, rotate your object that much.

This will be more efficient, too.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-19-2006 14:48
2 problems

1 super fast timers usually cause more lag than they can cope with

2
From: lsl wiki llSetRot

Note: This function delays the script for 0.2 seconds.


it wouldnt do anything but pile up and die :)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-19-2006 15:29
I picked up the following script someplace that uses llTargetOmega and llSetRot to give smooth rotation.

CODE
// Lex Neva
//
// Smooth Rotation

// This script demonstrates how to use llTargetOmega() to smoothly transition between two
// rotations. Occasionally the object will under- or over-rotate, but generally, the effect
// is to rotate smoothly between a starting and ending rotation.


// how long to take to rotate
float ROT_TIME=1.0;

// axis to rotate around
vector ROT_AXIS=<0.0,0,1>;

// angle in radians to rotate
float ROT_ANGLE=PI_BY_TWO;

// initial rotation
rotation ROT_START=ZERO_ROTATION;

default
{
state_entry() {
// this needs to be a unit vector
ROT_AXIS = llVecNorm(ROT_AXIS);

// get the process started
llSetRot(ROT_START * llAxisAngle2Rot(ROT_AXIS, ROT_ANGLE));
state unflipped;
}
}

state unflipped {
state_entry()
{
llTargetOmega(ROT_AXIS,-ROT_ANGLE/ROT_TIME,1);
llSleep(ROT_TIME);
llTargetOmega(ROT_AXIS,0,1);
llSetRot(ROT_START);
}

touch_start(integer total_number)
{
state flipped;
}
}

state flipped {
state_entry()
{
llTargetOmega(ROT_AXIS,ROT_ANGLE/ROT_TIME,1);
llSleep(ROT_TIME);
llTargetOmega(ROT_AXIS,0,1);
llSetRot(ROT_START * llAxisAngle2Rot(ROT_AXIS, ROT_ANGLE));
}

touch_start(integer total_number)
{
state unflipped;
}
}
Joakim Yakan
Fast learner
Join date: 2 Oct 2006
Posts: 31
10-19-2006 22:55
Thanks again!