Make the bullet in a 2d Top Down shooter get destroyed after passing mouse position

Hello everyone!

I’m making a 2d top down shooter game and I want the bullet to be destroyed after passing the mouse position that’s set after clicking the mouse to shoot(I want to simulate the player shooting at that point not just in the direction of the mouse), but I don’t know how could I accomplish this.

Note: The bullets are created as objects and not raycasted and they have a random spread so they won’t always be going exactly through the mouse position
Thanks in advance! :slight_smile:

With random spread you would probably have to calculate the distance. Luckily there is a Vector3.Distance method you can use. Just take the distance from the mouse click and player, feed it to your bullet script and then check if your bullet is at greater distance than what you gave it. If it is, destroy it

You can use Vector3.Project if I’m not mistaken.
vector is shoot origin towards the mouse and onNormal is the shoot direction. If the lenght of the resulting vector is shorter than the length of the traveled shoot direction, the bullet has bypassed the mouse as in orthogonally bypassed and you can destroy it.