Jump to content

Rez to Face Global Coordinates


Moon Corrigible
 Share

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

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

Recommended Posts

My brain stopped.  :)

 

I am making a rezzer which will create pillows for people to lay around and participate in a discussion.  So far, it talks to the person to find out what sort of pillow they want, then does a sensor sweep to find out where they are standing (in case they moved after touching the object), and rezzes the type of pillow they want under their feet.  That all works hunky dory peachy keen.  

 

So I know the global coordinates that the pillow is rezzed at.  And I know the global coordinates that I would like the pillow to face (to have the x axis point toward).  But for the life of me I can not figure out how to tell what rotation to rez the object at so that it faces those global coordinates. 

 

sensor(integer num_detected)
    {
        vector av_pos = llDetectedPos(0);
        
        vector size = llGetAgentSize(llDetectedKey(0));
        float floor = (size.z + 0.05)/2;
        
        vector rez_pos = <av_pos.x, av_pos.y, av_pos.z - floor>;
        
       
        llRezAtRoot(chosen, rez_pos, llGetVel(), llGetRot(), dialogchannel);
    }

Link to comment
Share on other sites

It wouldn't work in a majority of cases, because if the agent is further than 10m from the rezzer (assuming the rezzer is not a megaprim) llRezAtRoot() will silently fail. To avoid this, the rezzer should rez at zero_vector offset and then tell the rezzed pillow agent's coordinates so it could move there.

In fact I've recently made a pillows rezzer for a client (doesn't have exlusive) so if you want it too, call me in-world

Link to comment
Share on other sites

As written, your rezzed object will have the same global rotation as the rezzer (llGetRot()) .  If you want it to face a particular spot when rezzed, you need to calculate the angle of rotation first.

float Angle = llAngleBetween( <1.0,0.0,0.0>, llVecNorm( new_pos - llGetPos()) );

Then you need to apply that angle to a rotation around your object's Z axis

rotation New_Rot = llAxisAngle2Rot(<0.0,0.0,1.0>, Angle);

That's the global rotation that your rezzed object should have when it is rezzed. 

Of course, you might want to solve a much simpler problem.  Since you already know where your target av is and which way he's facing, you can set the new object's rotation relative to that.  For example, if you just set its rotation to llDetectedRot(0), then its X-axis will be facing the same way that the av's is.  If you want it to face the av instead, then its rotation should be

//Euler2Rot(,0.0,0.0,PI> * llDetectedRot(0)

/me  can't get in world to verify, so has her fingers crossed.

ETA:  As Ela points out, your method won't work beyond 10m from the rezzer, so take her suggestion and just rez it next to the rezzer and then relocate it with llSetRot and llSetRegionPos .  Thanks, Ela.

Link to comment
Share on other sites

Oh my brain started working again... it hurts!  it hurts!  - hehehehee

 

Having the object get the rotation from the avatar information is BRILLIANT and something I never would have thought of!  Thank you!!

 

And ..(how sad is this) .. I was thinking that i would have to script a runner to go out 10 m and then rez from there - or repeat however many times until it got within range and then rez.   Having the pillow move to the person is SUCH a better idea!  Thank you all so much!!!

 

Link to comment
Share on other sites

llSetRegionPos was released across the grid with server upgrades in the week of 2012-1-30:

"New LSL function integer llSetRegionPos(vector position)The object with the script will move the root prim position to the given location. The position is any position within the region. If the position is below ground, it will be set to the ground level at that X,Y spot. The function has no delay or throttle.

  • Returns 1 if the object is successfully placed within 0.1 m of position.
  • Returns 0 and does not move the object if position is more than 10m off region or above 4096m.
  • Returns 0 and does not move the object if the object is dynamic (has physics enabled).
  • Returns 0 and does not move the object if the object can not move to position due to object entry rules, prim limits, bans, etc "

I have used it successfully in scripts that I have tested now on 6 main channel sims.

Link to comment
Share on other sites

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