- Home /
I Want To Shoot Bullets Correctly.
Hello Everyone! so not very long ago i asked a question and based on what's seen or what seems obvious it was not asked correctly so let me explain again, so basically i want to shoot bullets with a gun. by bullets i mean real bullets not a raycast or something and if someone tell me that i did not do the research before i did but it is not what i want i basically want karlson style bullet shoot because in video lessons the bullets are sometimes not straight and sometimes the bullets collider pushes me back and other things so please help me again i want a karlson style bullet shoot.
-thanks-
Also if you are going to do it the way Llama explained you will need to make sure that you are writing move forward for the bullet in the fixedupdate so it will have the same bullet speed for each player playing regardless of the FPS,
Answer by Llama_w_2Ls · Jan 02 at 04:36 PM
Just instantiate a bullet at the nozzle transform of the gun and have a script that moves it forward by a small amount every frame in the direction it's looking.
Bullets move very quickly, so collision detection won't be as accurate at faster speeds, so you inevitably need to raycast every frame by a small distance in the direction of the bullet to detect collisions. What the raycast hits is the end position of the bullet.
Now the bullet doesn't even need a collider so you don't need to worry about physics glitches. The only issue may be that the bullet accidentally hits yourself. You can limit what layers the bullet raycast may hit as a parameter in the raycast function. @adampromen1
Answer by JethRow · Jan 04 at 03:56 PM
But another way to do it is alot simpler, you create a bullet prefab with a rigidbody that isn't affected by gravity or drag, therefore when you instantiate you can apply velocity to the direction of the barrel by making a emty object at the barrel end, this will increase the performance of shooting as you won't be needing to do it in update script but rather only once , when it is insantiated, specially if at some point if you are going to be making machine gun that is shooting like few bullets per second, chances are you will have like 10 bullets in the scene that are using update function and slowing down your game, so i would reccomend you to do it this way
Your answer
Follow this Question
Related Questions
Bullet does not move forward after being initiated 1 Answer
Advanced FPS shooting 1 Answer
How to make 3 bullets fire at different angles 1 Answer
Shooting problem Unity3D C# 0 Answers
Predict Collision 0 Answers