- Home /
Shooting. Bullet floats and sprays
Hi. I know this might sound silly... I've read the FPS tutorial and all sorts of tutorials... But when I shoot, the bullet stays at the spawn point of the gun. And you shoot millions of them as long as you keep holding on the mouse button. Here's my script:
public var bulletPrefab : Transform; public var bulletSpeed : float = 6000;
function Update(){ if(Input.GetButton("Fire1")) { if(!bulletPrefab || !bulletSpeed) { Debug.Log("[Shoot] 'bulletPrefab' or 'bulletSpeed' is undefined"); }else{ var bulletCreate = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint").transform.position, Quaternion.identity); bulletCreate.rigidbody.AddForce(transform.forward * bulletSpeed); } } }
Please help!
at the moment when you hold the mouse button it instantiates 1 bellet every 0 seconds thats why you get thousands, you try ins$$anonymous$$d of 'if(Input.GetButton("Fire1"))' 'if(Input.GetButtonDown("Fire1"))' this means you click every time to fire a bullet but is you want to hold down to fire quickly (but not so quickly) you could try using a Coroutine to run the script every 0.1 seconds.
Answer by TheokieZA · Nov 30, 2010 at 07:59 AM
Hi,
It should be
Input.GetButtonDown("Fire1")
Also does your bullet prefab have a rigidbody attached? Maybe thats why it doesn't move?
Your answer
Follow this Question
Related Questions
Bullet Drop With Raycast 4 Answers
how to make bullets apply damage 1 Answer
When reloading my gun sounds and the bullets glitch out. 2 Answers
How do i make a fps where the gun always shoots realisticly 3 Answers
Shooting & Animation Problem 1 Answer