- Home /
Help with fire script
When I shoot the gun it only shoots one way no matter what direction I'm facing
My script on the gun
public GameObject bullet;
public float fireRate = 10f;
private float nextFire = 0.0f;
public float bulletSpeed = 100f;
void Update()
{
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time +firerate;
GameObject Bullet = Instantiate(bullet, transform.position, transform.rotation) as GameObject;
Bullet.rigidbody.AddForce(Vector3.forward * bulletSpeed);
}
}
}
My script on the bullet
Public GameObject spawnPoint;
void Update ()
{
Destroy (gameObject, 5);
}
Void FixedUpdate()
{
rigidbody..AddForce(Vector3.forward * 100);
}
}
Answer by DubstepDragon · Jun 05, 2013 at 04:04 PM
That is a common problem with collision detection. Please refer to this page on how to fix this issue:
How to ignore collision in Unity3d so as to stop projectiles moving at unwanted angles.
If this is not the problem you have, then you must elaborate a bit more, at least with screenshots or a video if possible.
Tell me if that fixes your issue, glad to help with anything else.
If that doesn't work, then I can supply you with a very simple script that I have.
Your answer
Follow this Question
Related Questions
How to add sound to gun shot script 4 Answers
How can I shoot bullets that you can aim with the crosshair? 1 Answer
Shooting script problem. 2 Answers
Using raycast gun to take down life of enemy when shot 1 Answer
FPS aim marker Question 0 Answers