- Home /
How do i make my character rotate when falling?
I want to transmit air resistanse sense in my game, not only gravity.
So, when character is falling - it is not just falling down, but gliding the air. I want to rotate my character up to 90 degrees down when it is falling and back when player adds some force to go glide up & forward. Please see image attached as example.
My idea is to use "falling" speed to calculate rotation angle, but i am not sure it is correct way to do that. What is the correct way to achieve that?
P.S. Sorry, yes, of course is use rigidBody2d.
Answer by robertbu · Mar 29, 2014 at 03:19 PM
You don't give a lot of details about your situation. Assuming you are using a Rigidbody, an easy solution is to have your character's rotation follow the velocity:
var dir = rigidbody.velocity;
if (dir != Vector3.zero)
transform.rotation = Quaternion.LookRotation(dir);
The code is a bit different for 2D, but the concept is the same.
im using c# what is Dir. what should i replace there. i used this script. but an error C:\Users\Cha\Documents\RescueEgg\Assets\Scripts\PlayerScripts\Player$$anonymous$$ovement.cs(7,7): Error CS0121: The call is ambiguous between the following methods or properties: 'UnityEngine.Vector2.operator !=(UnityEngine.Vector2, UnityEngine.Vector2)' and 'UnityEngine.Vector3.operator !=(UnityEngine.Vector3, UnityEngine.Vector3)' (CS0121) (Assembly-CSharp)