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 ?

有帮助吗?

解决方案 2

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top