Bullets not hitting mouse position all the time in 2D shooter

Hello all. I’m making a little shooting game in an effort to learn Unity. The idea is to shoot at the mouse position whilst controlling the player with WASD. I want the bullets to ‘hit’ wherever the mouse pointer was when the fire button is pressed.

To accomplish this, the bullet sprite destroys itself after an amount of time. That time is determined by getting the magnitude of the vector between gun and mouse and dividing by the speed of the projectile.

For some reason that I am unable to fathom (despite hours of trying) the bullet does not always stop at the mouse pointer. Sometimes it falls short. This effect is magnified if the force on the bullet is increased: with a “bulletforce” of 1, the bullet always seems to hit the pointer position. A “bulletforce” of 150 and it can be off by a huge amount.

I’ve added a pic of the bit of code responsible. Any help would be gratefully received: This is giving me a massive headache and am considering throwing my laptop in a lake.

(Apologies for ugly code: I’ve been tinkering with it all day)

First up, this should be in Scripting, not General Discussion.

Second, rather than screenies, just paste your code between a pair of [c o d e] [/ c o d e] tags.

Third, a potential answer to your question: “force” is not “speed”, though under certain circumstances they could get the same result. Two things to consider:

  1. Is drag enabled?
  2. While the manual recommends against it, this could be a case where directly setting velocity is a better approach.