Question by
pinkyking256 · Jun 10, 2020 at 05:01 PM ·
2d2d game
Rotate rigidbody2D towards direction of movement?
Here is my code:
public Rigidbody2D rb;
public float speed = -20f;
void Start()
{
float randomAngle = Random.Range(-2.5f, 2.5f);
rb.velocity = (transform.up + transform.right * randomAngle).normalized * speed;
}
How would I rotate the object towards the randomAngle, or the direction it's moving? There are about a hundred answers on the internet and not a single one seemed to work for me.
Comment
Your answer
Follow this Question
Related Questions
Is it possible to make gameobject size around irregularly shaped .pngs? 0 Answers
One large 2d grid or multiple small ones? 1 Answer
Virtual controller and fire bullet shot in 2D 0 Answers
How do I change the orientation of my game to portrait? 0 Answers
Having troubles with the checkpoints opening on my 2D platformer and its making my sprite dissapear. 1 Answer