Jump to content

How to make a physical object always face up, but keep it's forward and left rotations the same?


Gawain Galtier
 Share

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

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

Recommended Posts

Hello! I'm new to rotations and trying to learn. It looks tough!

I was wondering if there is a way to make a physical object always face up, but keep it's forward and left rotations the same? (just face up and not effect the other 2 axis)

I am trying to rez an object that needs to always be completely vertical, but it's global forward and left rotations shouldn't change.

I have tried testing it with llRotLookAt, on a touch event, and I can get it to face up, but it always rotates on the axis as well.

Here is the base code I was trying to isolate the axis and learn from:

default
{
    state_entry()
    {
    }

    touch_start(integer total_number)
    { 
        vector detected = llDetectedPos( 0 );
        vector pos = llGetPos();
        llRotLookAt( llRotBetween( <0.0, 1.0, 0.0>, llVecNorm( <detected.x, detected.y, pos.z> - pos ) ), 1.0, 0.4 );
    }
}

 

Link to comment
Share on other sites

Zeroes?  Whenever you write a vector, you are using Cartesian coordinates <x, y, z>.  If your object is to rotate the local Z axis (<0.0,0.0,1.0>) up, then you want to get the rotation between <0.0,0.0,1.0> and where that axis is currently pointing ( <0.0,0.0,1.0>*llGetLocalRot() ) and then correct the local rotation by that amount.  For a single prim, it doesn't make any difference whether you write that in terms of local rotations or global rotations, but it's worth keeping the local frame of reference in mind anyway.

BTW, I failed to notice that you said you're working with a physical object.  In that case, you can't use llSetRot or llSetLocalRot, which have no effect on physical objects.  You can switch to non-physical periodically, however.  Then make the correction, if necessary, and go physical again.  While the object is physical, use llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y,FALSE) to keep the object upright.

  • Like 1
Link to comment
Share on other sites

Thank you so much again Rolig! I have to study that.

And with your help, I came up with the following (and it is working so far):

//object set to physical prior to new rez

orient_up(){ llSetLinkPrimitiveParamsFast( LINK_THIS, [ PRIM_PHYSICS, FALSE] ); llSleep(0.1); llSetLocalRot( llGetLocalRot() * llRotBetween( <0.0, 0.0,1.0> *llGetLocalRot(), <0.0, 0.0,1.0> ) ); llSay(0,"collision");//debug} default{ state_entry() { llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y,FALSE); } collision_start(integer vIntCollided) { integer vBitType; do { vBitType = llDetectedType( --vIntCollided ); if (vBitType & AGENT_BY_LEGACY_NAME) { //do nothing } if (vBitType & PASSIVE) { orient_up(); } } while (vIntCollided); } land_collision(vector pos) { orient_up(); } touch_start(integer total_number) { if (llDetectedKey(0) == llGetOwner() && llGetTime() > 1.0) { //re-adjust function llSetLinkPrimitiveParamsFast( LINK_THIS, [ PRIM_PHYSICS, TRUE] ); llSleep(1.0); orient_up(); llSay(0,"touched");//debug } }}

 Thank you again

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3532 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...