Make bullet face direction of movement
I have wrote this:
private void Update()
{
transform.LookAt(transform.position + transform.InverseTransformDirection(GetComponent<Rigidbody>().velocity));
}
to make my bullet (rocket) face direction of movement, because of the particles. Unfortunelly there is some sort of bug that keeps bullet face wrong direction, so it emitts particles the wrong way:
The bullet looks like this (projectile is moving, and child object emmits particles):
I use
shotProjectile.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0, 0, projectileVelocity * 2));
to shoot it.
Any idea how to fix this/make bullet face direction of movement? Thanks.
Comment
Best Answer
Answer by Hellium · Jan 07 at 07:57 PM
rigidbody.velocity
is already a world vector, why calling InverseTransformDirection
?
transform.LookAt(transform.position + GetComponent<Rigidbody>().velocity);
or
transform.rotation = Quaternion.LookRotation(GetComponent<Rigidbody>().velocity);
I was just so desperate that i copied some code from forum and it partly worked. Thanks for your answer.