Jump to content
Sign in to follow this  
khonsuu

rotate to line up with arbitrary vector.

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).

Share this post


Link to post
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)

Share this post


Link to post
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);

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...