- Home /
Bullet still goes sideways...
I maded a script but still it doesn't work can someone help me please?
Here's the script:
var BulletPrefab:Transform; var force : float = 2000;
function Update() { if(Input.GetButtonDown("Fire1")) { var bullet = Instantiate(BulletPrefab,
GameObject.Find("Barrel").transform.position,
GameObject.Find("Revolver").transform.rotation);
bullet.rigidbody.AddForce(transform.forward * force);
} }
What do you mean by "it doesn't work"? Do you get compilation error? What do you expect your script to do?
Answer by Muuskii · Jul 20, 2012 at 04:04 PM
You're using transform.forward as the force direction. The bullet will fly in the direction that the object that holds this script is facing, as opposed to the direction your revolver is facing.
What happens when you use:
bullet.rigidbody.AddForce(GameObject.Find("Revolver").transform.forward * force);
P.S. are you sure you don't want to use hitscan for a revolver? They move pretty fast.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074447im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Dart/Bullet comes out pointing up 1 Answer
bullets wont show up 1 Answer
Help with gun scripting!? 1 Answer
Bullet Hole not inline with sight?(Center of Screen) 1 Answer