Jump to content

trying to get an object to rotate 90 degrees


Christina Halpin
 Share

You are about to reply to a thread that has been inactive for 396 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

In theory this rotates an obect 90 degrees around the z-axis.

    llTargetOmega(<.0,.0,1.0>,PI/(2.0*rotationtime),1.0);
    llSleep(rotationtime);
 

I think the math is right, because it sometimes does 90 degrees. But it sometimes falls a little short (and then errors accumulate).

Is there a way I can fix that?

Otherwise, I could use a command that tells me which direction the object is facing. I think. (It should be in LlGetObjectDetails, but apparently is not.)

Thanks.

Link to comment
Share on other sites

"Rotate" isn't exactly the right word in this context.  llTargetOmega spins the object continually around the local axis that you define for it.  If you simply want the object to turn 90 degrees and then stop, you ought to be using llSetRot or llSetLocalRot, or using appropriate parameters with llSetLinkPrimitiveParams.  

If you truly do want the object to spin around its local Z axis, or if you are using it in a script that creates a slow, smooth rotation, then you will indeed find that it's not 100% precise.  You will end up with roundoff errors.  For that reason, it's a good idea to end the movement by using llSetRot  (or another appropriate function) to set the object's final rotation accurately.  The problem is that llTargetOmega is doing its work client-side.  As far as the servers are concerned, the object is not rotating at all. They will set the object's actual rotation as closely as possible (given the accumulated errors) when you stop llTargetOmega

You can get the object's current rotation with llGetLinkPrimitiveParams, using either PRIM_ROTATION or PRIM_ROT_LOCAL as appropriate.  Then perform the target rotation, llEuler2Rot(<0.0,0.0,PI/2>) * current_rot, with the appropriate rotation function.

  • Thanks 1
Link to comment
Share on other sites

Ugh, actually I tried that before, and now I am running into the same problem. The following, and every variation I can think of, just gives me a zero rotation no matter which direction the object and I are facing.

list templist = llGetObjectDetails( llGetKey(),[OBJECT_ROT] );
string rotobj = llList2String(templist,0);
llOwnerSay ("facing towards " + rotobj);
 

 

Link to comment
Share on other sites

thanks Fenix. I had tried a more complicated version, and yours was simpler, but they both seemed very inconsistent in how far the spining went (or they paused).

I also got an error with both "Cannot use a script to move a linkset while it is playing an animation. Stop the animation first.." I do not know what that is. But thnks again.

Link to comment
Share on other sites

Yup, there are several caveats to KFM, and that is one of them (see the wiki page I linked above for all of them). You can't use scripted commands to move any part of the linkset while the KFM is going. You need to wait for it to fully complete or stop it with one of the KFM commands. In fact, that's how several of the smooth door rotation examples work if I recall correctly.

Link to comment
Share on other sites

2 hours ago, Christina Halpin said:

rotates an object 90 degrees around the z-axis.

// setup.

float angle = 90.0;
vector axis = <0,0,1>;
float time = 2.0;
integer reps = 4;

// convert units.

angle *= DEG_TO_RAD/ reps;
time = time/reps;
rotation r = llAxisAngle2Rot(axis, angle);
while(~--reps)
{   llResetTime();
  	llSetRot(llGetRot()*r); // swap r and llGetRot() to rotate on the objects own z-axis.
 	// llSetRot has a 0.2 forced delay. 
 	llSleep(time-llGetTime());
}

or so is a not so uncommon technique.

Edited by Quistess Alpha
Link to comment
Share on other sites

It is a bench with poses.

I think I understand. If I use llGetRot() to find out if it has rotated the full 90 degrees, I will get back the answer that it hasn't rotated at al, it's still at the starting position. Because the almost 90 degree rotation I see on my screen is "client-side". (Because I was using llTargetOmega.)

Edited by Christina Halpin
  • Like 2
Link to comment
Share on other sites

1 minute ago, Christina Halpin said:

If I use llGetRot() to find out if it has rotated the full 90 degrees, I will get back the answer that it hasn't rotated at al, it's still at the starting position. Because the almost 90 degree rotation I see on my screen is "client-side".

Right. So you can use llTargetOmega to do the slow apparent rotation client-side.  Simultaneously, use a method like the one that Tessa suggested to do the actual rotation in three or four steps.  If you time things so that the llTargetOmega action takes exactly the same time that the stepped rotations do, the result will be a smooth rotation that stops on a dime --- right where you want it.  That's the way some of the popular smooth-rotating doors work.  Toy Wiley wrote one of the earliest LSL scripts that use this approach.  You'll find an updated version in the wiki at https://wiki.secondlife.com/wiki/Smooth_Rotating_Door if you want to study how he did it.

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

After some experimenting I found that this works:

 

vector rot_old = llRot2Euler( llGetRot() ) * RAD_TO_DEG;                            // get the original rotation in Euler format
vector rot_new = rot_old + <0,0,1>;                                                                  // calculate new rotation, turned 90 DEG over Z-axis

llSetLinkPrimitiveParamsFast( LINK_THIS, [ PRIM_ROTATION, <1,0,0,1> * llEuler2Rot( rot_new * DEG_TO_RAD ) ] );   // apply new rotation

 

good luck!,

RJ

Edited by RJ Muni
  • Confused 1
Link to comment
Share on other sites

2 hours ago, RJ Muni said:

vector rot_old = llRot2Euler( llGetRot() ) * RAD_TO_DEG;                            // get the original rotation in Euler format
vector rot_new = rot_old + <0,0,1>;                                                                  // calculate new rotation, turned 90 DEG over Z-axis

llSetLinkPrimitiveParamsFast( LINK_THIS, [ PRIM_ROTATION, <1,0,0,1> * llEuler2Rot( rot_new * DEG_TO_RAD ) ] );   // apply new rotation

 

I think that's more-or-less just

llSetRot(<1,0,0,1>*llGetRot()); // rotate 90 degrees on intrinsic x-axis

with some obfuscation thrown in. <1,0,0,1> is a non-normalized 90-degree x-axis rotation.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 396 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...