Pregunta

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 ?

¿Fue útil?

Solución 2

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top