I have recently made the simplest gun and bullet script that I could and it works amazingly, except for one problem that I've found. When I attach it to a game object with a rigid body the force of the bullets move the object back with quit a bit of force.
But what I can't seem to figure out is why the bullets are imparting force on the object at all. The bullets do not have a rigid body component. The way my guns work is with two scripts, one which acts as a simple spawning point when a key down event is given and what ever object you give it to spawn.
The second script is applied to the bullet itself which causes the bullet to have motion through transform.Translate
with a speed variable. The best example I can give of this is when I attached two guns to the default unity jet and when I fired, it had enough force to move the jet back against its thrust speed.
I really would appreciate any help with this so I can move on with my project. I will provide the code bellow for the two scripts.
Thank you
public class Shoot : MonoBehaviour {
public GameObject bullet;
void Update () {
if (Input.GetKey (KeyCode.Mouse0))
Instantiate(bullet, transform.position, transform.rotation);
}
}
public class MoveBullet : MonoBehaviour {
public float speed = 1f;
void Update () {
transform.Translate (0, 0, speed);
}
}