Question by
ikazrima · Feb 03, 2016 at 03:38 PM ·
rotationvelocity2d sprites
Initial sprite rotation for velocity direction
I set up my sprite to face right initially, then use this code so that it faces the correct direction every time. (code modified from someone's answer here):
public void FaceVelocityDirection()
{
_rb2D.angularVelocity = 0;
Vector2 _dir = _rb2D.velocity;
float angle = Mathf.Atan2(_dir.y, _dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
Then I use this code to fire it up:
public void FireForward ()
{
_rb2D.AddForce (transform.up * 100 * _speed);
}
When I'm firing up, it is visibly seen at least one frame that the sprite faces the right direction, then after one frame update it rotates up. I place it in update and it can still be seen. Any advice on how to fix this?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612062516im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make One More Line game? 0 Answers
Rotate Rigidbody2D by Touch 1 Answer
Why is a gameobject moves at start? 0 Answers