Jump to content

rotate to line up with arbitrary vector.


khonsuu
 Share

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

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

Recommended Posts

I have an arbitrary unit vector and an object with zero rotation.  I want to rotate this object so that its negative X axis (X-)  lines up with the unit vector.  What is the script  to perform this?

 

I have an object which is currently at rotation =<0,0,0>  in its edit tabs.  Inside of the object's script is an arbitrary unit vector called Nface.  I would like to perform llSetRot() or similar in a script to make it line up with Nface.  That is , I want the object's  negative X-axis  to line up with Nface via a rotation.  What would be the code for this?


For ease of coding, it is possible to instead reverse Nface and then make the positve X-axis  (X+)  line up with it.  This might make the code significantly easier. (just a thought).

Link to comment
Share on other sites

       vector pos = llGetPos();
       vector Target = Nface;
       llRotLookAt( llRotBetween( <-1.0, 0.0, 0.0>, llVecNorm( <Target.x, Target.y, pos.z> - pos ) )  , 1.0, 0.5 );

// choose which face to use with <-1.0, 0.0, 0.0> (this is negative x)

//                                                           <0.0, 1.0, 0.0> (this is positive y)

Link to comment
Share on other sites

Dear Xiija,


Thanks for the reply. You helped to point me in the right direction. (insert dry pun)

It seems the command I needed was something more like ths.

llRotLookAt(    llRotBetween(<-1.0, 0.0, 0.0>,  Nface),    1.0,      0.4);

Link to comment
Share on other sites

Yes, that will work.  Typically, though, it's wise to look at the angle between <-1.0,0.0,0.0> and llVecNorm(Nface), because llVecNorm normalizes the target vector, thus scaling it to the same magnitude as your start vector.  It makes for neater math. 

Link to comment
Share on other sites

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