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 () {
%|-829671820_1|%
%|52666472_2|%
%|1809783453_3|%
%|-1054893234_4|%
%|1058131029_5|%

%|-490803135_6|%
// object’s Z axis
%|-112405093_8|%
%|-1590855618_9|%
}
`

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:

70263-ildl2uz.png

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

Change

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

to

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.

[SerializeField]
private Rigidbody cube;
[SerializeField]
private float speed = 100f;

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

        cube.transform.localPosition = Vector3.zero;
        cube.velocity = cube.transform.forward * speed;
    }
}