- Home /
Tilt player on movement
Okay so I'm making a simple 2d game and I want my player to tilt a bit to the direction he is moving to. my problem is that the player doesn't tilt back to 0 (angles- the origin) after he moved.
void updateROT()
{
if (Input.GetAxisRaw ("Horizontal") > 0 || Input.GetAxisRaw ("Horizontal") < 0)
{
current = Vector3.Lerp (current, upV3, Time.deltaTime * rotationSpeed);
}
else
{
current = Vector3.Lerp (current, origin, Time.deltaTime * rotationSpeed);
}
}
*The if opposite I know you could do != 0 but i just changed temporary
When I run the game and start moving the player he tilts normally but when I stop him he stays tillted...
Thanks in advanced!
And also do I need to fix the angle of the rigidbody or not?
It's hard to tell whats happening without the rest of your code. Are current, upV3 and origin euler angles??
Assu$$anonymous$$g that they are, try this ins$$anonymous$$d:
transform.eulerAngles = Vector3.Lerp( current, upV3, Time.deltaTime * rotationSpeed);
This being said, I have no idea what you are doing with current, origin and upV3 outside of this little code snippet that you have provided.
Providing more of your code will help to better understand your issue
Answer by haim96 · Mar 06, 2014 at 07:49 AM
i can't help you with code at this point of time but maybe i can direct you to an answer. when i had problem with my player rotation i looked for answer and found that the best way to tilt is to parent your player to controller object (some empty gameobjet) and while the empty parent control the X and Y movement you free to tilt the child object (your player) without effecting his movement direction. the tilt it self can be done by starting coroutine that match the tilt direction to the parent direction and velocity. hope it help you some how...
Your answer
Follow this Question
Related Questions
Glitchy collisions 0 Answers
How to make a circular 2D map. 2 Answers
Horizontal Input 1 Answer
How do I automatically go diagonally when hitting a diagonal? 1 Answer
Horizontal axis to touch input 0 Answers