- Home /
How do I make my Projectile rotate towards its direction?
Beginner here, for learning purposes I made a Turret that instantiates a Capsule Rigid Body in front of it and adds Force. My problem is that the Capsule that I shoot doesnt rotate in mid air.
Imagine shooting an Arrow with a Bow slightly upwards, you expect the arrowhead to point upwards at first and slowly rotate downwards and its head hits the ground first.
How do I make my Capsule Rigid Body Projectile face towards the direction it is going?
So I instantiate my Bullet like this:
void Update ()
{
if(Input.GetButtonDown("Fire1"))
{
Rigidbody BulletInstance;
BulletInstance = Instantiate(Bullet, MuzzlePoint.position, Muzzle.rotation) as Rigidbody;
BulletInstance.AddForce(MuzzlePoint.forward * speed);
}
}
And I hoped I could just add a Script to the Bullet Prefab that could say something like: "The Rotation of the Bullet's X axis = Direction the Bullet is flying towards" and put this in a fixedUpdate function.
This is a non-standard way to handle such a projectile, but consider trying:
body.transform.LookAt( body.transform.position + body.velocity );
The traditional approach to such a projectile would not include rigidbodies.