Search code examples
3dunity-game-enginegame-physicsprojectile

Projectile Rotation in Unity3D


I want to simulate a projectile motion. I use the following Code

 if (Input.GetButtonDown("Fire1")) {
        Rigidbody clone;
        clone = Instantiate(projectile, transform.position+ new Vector3(0f,0f,2f), transform.rotation) as Rigidbody;
        clone.velocity = transform.TransformDirection(Vector3.forward * Speed);
    }

My projectile is a rigidbody and I want it to set its orientation like real projectile means when my projectile is about to collide with ground it should face ground not its launcher's rotation. it should change its rotation based on its speed. I don't know how to do that ?


Solution

  • Now it is working :) this line of code transform.LookAt(transform.position + rigidbody.velocity); solved my problem