- Home /
The question is answered, right answer was accepted
How can you make a 2D object move based on rotation, and rotate while moving?
Basically, I have a missile-like object that I'd like to rotate while moving. I know how to make it move based off of rotation initially, but that only works in a straight line, and I would like to have it reorientate and adjust itself while in motion. I already have it rotate and move but the mid-flight rotation doesn't seem to affect how it moves at all.
void Update()
{
Vector2 direction = player.transform.position - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotateSpeed);
transform.Translate(transform.right * Time.deltaTime * speed);
}
Answer by Nomron · Mar 10, 2019 at 11:03 PM
Nevermind, the line rb.velocity = transform.right * speed;
works great. Sorry!
Follow this Question
Related Questions
Bullet dissapears from screen when I use LookAt? 0 Answers
gameobject stops moving correctly when rotating 1 Answer
How do I rotate a bullet (arrow) in Unity 2D? 0 Answers
In unity 2D c# how to rotate an object like geometry dash? 1 Answer
how to rotate a gameobject in a given direction and stop when it's done 1 Answer