- Home /
Bullet Fire script not working
Im making a mulitplayer shooter and when i shoot it fires out of the barrel using the spawnpoint i made but then it shoots really fast out of another location please help!
EDIT!!!! i tried changing the code to getbuttondown but it still fires out of the barrel plus the mag!
This is my code:
var projectile : Rigidbody;
var speed = 20;
function Update () {
if ( Input.GetButton ("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 2);
}}
Answer by Muzz5 · May 25, 2011 at 05:24 PM
A few points (will look at it more if none of these work): 1. Is the script applied to the gun? If not, do so. If it is, try using transform.position + Vector3(Insert Length of the barrel / 2). This will make it come out of the end. Or you could just have an empty gameObject at the end of your barrel. 2. Try putting var before the first clone perhaps? 3. I'd be tempted to use GetButtonDown instead of GetButton, if you want the player to click for each shot.
Your answer
Follow this Question
Related Questions
Bleeding and Health Generation Skript 1 Answer
Restricted Area 2 Answers
2D bullet script errors. 1 Answer
[Closed] MainMenu Script error 2 Answers
collider doesnt react to script 0 Answers