Search Unity

Rotate Rigidbody toward mouse

Discussion in 'Scripting' started by CornDog, Mar 29, 2013.

  1. CornDog

    CornDog

    Joined:
    Nov 17, 2012
    Posts:
    13
    I am attempting to rotate a rigidbody (in 2D, I'm using the 2D Toolkit) to point at my mouse location. The rigidbody will be located at the center of the screen, and I have the angle of the mouse relative to the screen center, but I haven't been able to find any good suggestions on how to figure out how to get the relative angle of the rigidbody.
    I have done some pretty extensive Google searching on this topic and have not found anything helpful thus far.

    Any thoughts?
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I am not sure what you mean by relative angle of the rigidbody. What you need is, the rise and run between the mouse and rigidbody. From that, you can calculate the angle of the tangent. Then rotate the rigidbody to that angle.