Search Unity

Rotate rigidbody based on its movement

Discussion in 'Scripting' started by Tabu, Jul 14, 2010.

  1. Tabu

    Tabu

    Joined:
    Dec 3, 2008
    Posts:
    44
    Hey
    I am creating sort of a side-scroll "smash 'em up" game (but in 3d), and are currently experimenting with different controlschemes, however, I'm having a bit of a difficult time getting a particular idea to work.

    What I want to achieve is to rotate a character(with a rigidbody) towards the direction where it is moving. So for example, if I press the 'w' key, the character moves upwards(or inwards if you like), and rotates to look in that direction also.

    Movement is set, but the rotation is pretty difficult for me to figure out? If someone could just guide me in the general direction of what to use, i would reward you with happy thoughs, and the knowledge that you saved my day. I will post here, if I find the sollution :)
     
  2. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    Use an empty gameObject. You set it at north west east south of the character (and always in the direction of the movement). You want to walk to the north, you put the gameObject to the north of the character position. And the character rotate to look at it.

    Watch out for the referential.