Gun shooting help

I am creating a game where you are the starting as the unity jet object. There will be other planes that are enemies that are going to follow the player and shoot him. Right now I am trying to make the player shoot. Right now it instantiaites a yellow cube (tracer fire) and then the cube just falls. It goes forward but not nearly as fast as i want it to be. Also I don’t want it to drop, heres my code `

var Bullet : GameObject;
function Update () {

// object’s Z axis

Ensure that the Bullet gameobject prefab doesn’t have any gravity-applying components such as a Rigidbody. If it does, then disable gravity on that prefab in the inspector:


Also, ensure that you’re using the correct forward component:


clone.velocity = transform.TransformDirection (Vector3.forward);


clone.velocity = transform.TransformDirection (transform.forward);

and that SHOULD fix the issue.

First, as @phxvyper said, add a RigidBody to your bullet and cancel UseGravity. Your script should have encountered error since you can only control the velocity through RigidBody.

Second, you should check what the value of

transform.TransformDirection (Vector3.forward)

is. Actually, it’s (0, 0, 1). So small, right? This is why your bullet move slowly.

OK, so here’s the script that should work.

private Rigidbody cube;
private float speed = 100f;

private void Update () {
    if ( Input.GetKeyDown( KeyCode.Space ) ) {
        Rigidbody clone = Instantiate( cube );

        cube.transform.localPosition =;
        cube.velocity = cube.transform.forward * speed;