bullet falls to ground

this is my script

var projectile : GameObject;
function Update () {
    if (Input.GetButtonDown("Fire1")) {
        var clone : Rigidbody;
        clone = Instantiate(projectile, transform.position, transform.rotation);
		
        clone.velocity = transform.TransformDirection (Vector3.forward * -120);
    }
}

someone plz tell me why my bullet doesnt shoot and just falls to the ground

2 Answers

2

I think the direction of the velocity you want to give it is simply clone.forward * magnitude.

still falls to the ground?

i tried attaching the move thing to my bullet function Start () { velocity = transform.forward * -120; }

What you want to do is use

clone.AddForce(transform.TransformDirection (Vector3.forward * -120));

instead of

clone.velocity = transform.TransformDirection (Vector3.forward * -120);

This should solve your problem!

-Aj

dont worry i fixed it by cloning a gameobject instead of a prefab, anyway it says BCE0019: 'AddForce' is not a member of 'UnityEngine.GameObject'.

velocity and AddForce are members of rigidbody, not gameobject. I think you are looking for clone.rigidbody.AddForce(transform.forward * -120, ForceMode.Impulse);

var clone : Rigidbody;