Question

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 ?

Was it helpful?

Solution 2

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

OTHER TIPS

As you said yourself in the comment, just include transform.LookAt(transform.position + rigidbody.velocity); into the projectile controller update. Also make sure that you mark 'lock rotation' in rigidbody settings, because otherwise the physics system will try to rotate your rigidbody yourself and it may result in jittering, unrealistic behavior.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top