- Home /
Shooting causes character to shoot forward
I am just playing around with a basic FPS and i am very new to unity and scripting. I have a character and a script written to shoot a bullet from a spawn point right in front of the gun. When i shoot the bullet sometimes it causes my character to go flying forward across the screen. As of now i have a rigidbody on the character and the bullet. I also have a script that destroys the bullet after 1 second. Is there anything I can change to make my character to not fly forward?
The script I used for shooting is:
var Bullet : Transform; var bulletSpeed : float = 5000;
function Update () { if(Input.GetButtonDown("Shoot")) {var shoot = Instantiate(Bullet, GameObject.Find("SpawnPoint").transform.position, Quaternion.identity); shoot.rigidbody.AddForce(transform.forward * bulletSpeed);} }
Thanks for any help
Answer by BurningThumb · Feb 02, 2011 at 03:16 AM
Place the bullet and player on separate layers, then in the edit->project settings->physics uncheck collision between those layers in the matrix.
Your player is most likely colliding with your bullet.
Ok i have one more problem when i am moving forward and right nothing shoots. As of now i have "w" for forward and "d" for right. To shoot i am using "e" is there a way to fix that?
Answer by cbissett · Feb 02, 2011 at 03:46 AM
Ok i have one more problem when i am moving forward and right nothing shoots. As of now i have "w" for forward and "d" for right. To shoot i am using "e" is there a way to fix that?
Your answer
Follow this Question
Related Questions
Shooting Accuracy Problem 0 Answers
How do I make a 2d bullet object move towards the players original position when it is spawned? 2 Answers
transform.TransformDirection not working -- WHAT IM MISSISNG? 1 Answer
Predict Collision 0 Answers
need help with instantiating for making a bullet shoot 1 Answer