Why doesn’t this code fire bullets at the center of the screen?(sometimes it does , sometimes it doesn’t).Please help
4834631–464117–fire.cs (998 Bytes)
Why doesn’t this code fire bullets at the center of the screen?(sometimes it does , sometimes it doesn’t).Please help
4834631–464117–fire.cs (998 Bytes)
We need to know a little more. Is this script attached to a gun or the player? It helps to know where exactly transform.position is.
One common issue I have encountered with firing is the bullet instantiating inside the player’s collider.
Where should it fire you think? You instantiate a bullet at the fire position and it looks like a camera is at the same position and so it is designed.
The player is the “gun”.Should I instantianate the bullet a little bit further?
I believe it should fire at the center of the screen , where the camera is aimed
Have you tried using camera position in instantiate instead of seft transform position?
I instantianated at transform.position+Vector3.forward and it seems it works much better.(not perfect , but it doesn’t spray randomly all over the screen) .Thanks Whatson1998