- Home /
make player face in direction of active force
I have a character which moves based on the android tilt sensor.
rigidbody.AddForce (Input.acceleration.x,0,Input.acceleration.y);
I am experimenting with the idea of making the character "drift" around the level, perhaps firing a projectile in its forward direction. I either need to manipulate the acceleration values or read the active forces to create a vector3 relative to the player, then set the player's forward direction to it.
In simple terms, if I tilt the device forwards, the character will face and slide in that direction. If I then tilt it right, the player should face in that direction immediately while the momentum continues to carry it up the screen.
Answer by robertbu · Jul 17, 2013 at 06:18 AM
Try this:
var v3 = Vector3(Input.acceleration.x,0,Input.acceleration.y);
rigidbody.AddForce (v3);
transform.rotation = Quaternion.LookRotation(v3);
Your answer
Follow this Question
Related Questions
physics.gravity with tilt game 1 Answer
Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers
Make object stick to the ground in 2D 2 Answers
ForceMode.Acceleration estimated dst != covered dst with a single Addforce in effect 1 Answer
How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers