Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to constrain object to one plane?

Randolph Peccable
Registered User
Join date: 12 Jul 2007
Posts: 20
07-30-2007 16:37
I'm scripting a physical object that's intended to glide along the surface of water. I got some very helpful tips from this forum about using llSetHoverHeight to keep the object close to the surface, and the property ownership functions to keep it from running amok on my neighbors' property.

Now I'm faced with trying to keep it level. I'm randomly choosing a target on my property, rotating the object toward it using llLookAt, then using llMoveToTarget to send it on its way. I'm using at_target and timer events to set new targets. After a short period, the object ends up leaning either left or right (rotated around its forward axis).

I don't have the geometry chops to make sense of rotations, so I checked the object's rotation when it was oriented level, and now my main script uses llSetRot to reset the object back to that default rotation periodically. This works, but the object spends a fair amount of time off-kilter before the correction can be made. IF I understood how to correct only the x-axis part of a rotation, I'd make the correction more often, but my little hack reorients the object to its original facing, which looks funny if I do it too often.

I tried using llRotLookAt, but the object kept pointing the wrong axis at the target. I copied the code snippet from the LSL Wiki page for llLookAt and have managed to get it working, but I suspect my orientation problems are coming from somewhere in this area. Sooner or later, the object always manages to rotate around its forward axis.

So, I need a way to keep a moving object dead-level, no matter what. Suggestions?

Thank you.
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
07-30-2007 18:21
llSetStatus( STATUS_ROTATE_X|STATUS_ROTATE_Y, FALSE ); may be all you need

http://rpgstats.com/wiki/index.php?title=LlSetStatus

Otherwise you can manually calculate the z rotation to your target:

vector normal = target_pos - llGetPos();
llSetRot( llEuler2Rot(<0,0,llAtan2(normal.y,normal.x)>;) );
Randolph Peccable
Registered User
Join date: 12 Jul 2007
Posts: 20
07-30-2007 19:03
From: Masakazu Kojima
llSetStatus( STATUS_ROTATE_X|STATUS_ROTATE_Y, FALSE ); may be all you need

http://rpgstats.com/wiki/index.php?title=LlSetStatus

Otherwise you can manually calculate the z rotation to your target:

vector normal = target_pos - llGetPos();
llSetRot( llEuler2Rot(<0,0,llAtan2(normal.y,normal.x)>;) );



Excuse my noobness, but I'm getting bizarre results from constraining the x and y axes as you suggest. The object either doesn't turn at all, or turns in unexpected ways.

How do I identify which axis is which for the object? When I edit it in Edit mode, the axes shift around depending on how I've moved the object: X is the long axis one time, and one of the short ones the next.
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
07-30-2007 19:14
If you change the ruler mode on the edit window to local you should be able to see the object's local axes. If it's a linkset you may have to either select just the root prim, or switch to reference mode and press shift+g.
Randolph Peccable
Registered User
Join date: 12 Jul 2007
Posts: 20
07-30-2007 19:26
From: Masakazu Kojima
If you change the ruler mode on the edit window to local you should be able to see the object's local axes. If it's a linkset you may have to either select just the root prim, or switch to reference mode and press shift+g.



D'oh! I should have RTFM.

Thank you for all your help. I hope I can pass it along to someone else someday.
Randolph Peccable
Registered User
Join date: 12 Jul 2007
Posts: 20
07-31-2007 06:55
UPDATE:

llSetRot wouldn't work because my object is physical. No rotation occurred.

I replaced it with llRotLookAt as follows:

llRotLookAt(llEuler2Rot(<0,0,llAtan2(normal.y,normal.x)>;) , strength, damping);

with success.

Thanks again.