Hi
I’m trying to make a gun that fires missles according to gun’s direction (nothing new or original), but I met strange problem. I create missle as below:
GameObject m = (GameObject)Instantiate(missle, missleStartPosition.position, transform.rotation);
And now:
- When missle doesn’t have rigidbody component and I use on it
transform.Translate(Vector3.forward * speed);
everything works fine. But when I attach rigidbody to it and do either
GameObject m = (GameObject)Instantiate(missle, missleStartPosition.position, transform.rotation);
m.rigidbody.velocity = m.transform.forward * shootingPower;
or
GameObject m = (GameObject)Instantiate(missle, missleStartPosition.position, transform.rotation);
m.rigidbody.addForce(m.transform.forward * shootingPower);
It almost works only when m.transform.forward.x > 0.2 (then direction is only a bit shifted to the right). If 0 < x < 0.2 then missle flies a bit right (like x = 0.2) and when x < 0 then it flies like x = 0.
Rotation and direction seem to be ok. Checked with:
- just translate without rigidbody
- Debug.DrawRay
- it almost works for x > 0.2
What do I do wrong?