x


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

more ▼

asked Sep 06 '11 at 07:35 AM

sam32x gravatar image

sam32x
178 40 56 62

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Sep 06 '11 at 12:08 PM

Ariel J gravatar image

Ariel J
64 6 6 9

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'.

Sep 06 '11 at 12:42 PM sam32x

velocity and AddForce are members of rigidbody, not gameobject. I think you are looking for

clone.rigidbody.AddForce(transform.forward * -120, ForceMode.Impulse);
Sep 06 '11 at 01:35 PM SilverTabby
var clone : Rigidbody;
Sep 06 '11 at 01:37 PM Joshua
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Sep 06 '11 at 07:51 AM

Joshua gravatar image

Joshua
6.4k 19 25 71

still falls to the ground?

Sep 06 '11 at 11:21 AM sam32x

i tried attaching the move thing to my bullet

function Start () {
velocity = transform.forward * -120;
}
Sep 06 '11 at 11:37 AM sam32x
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1963
x446
x308
x57

asked: Sep 06 '11 at 07:35 AM

Seen: 758 times

Last Updated: Sep 06 '11 at 01:37 PM