- Home /
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
Answer by Joshua · Sep 06, 2011 at 07:51 AM
I think the direction of the velocity you want to give it is simply clone.forward * magnitude.
i tried attaching the move thing to my bullet
function Start () {
velocity = transform.forward * -120;
}
Answer by Ariel J · Sep 06, 2011 at 12:08 PM
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 ins$$anonymous$$d 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, Force$$anonymous$$ode.Impulse);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Bullet Hole not inline with sight?(Center of Screen) 1 Answer
Bullet still goes sideways... 1 Answer
Dart/Bullet comes out pointing up 1 Answer
bullets wont show up 1 Answer