Inacurrate Aiming

When you make a game and you aim using the mouse, sometimes it doesn’t go where it is supposed to.
Is the game.


Not sure what the question is to be honest. Is the question your asking…

“How do I make it so that when you shoot using the mouse cursor as the target, sometimes the bullet does not go exactly where you clicked?”

If yes, when you are shooting and determining the angle the shot goes at, have a few numbers and expressions:

Angle of fire +20
Angle of fire -20
A random number behaviour

Have the two numbers numbers pointed at the min and max of a random.

Then, when you fire, take the angle of the shot from the randoms output, rather than directly from wherever your getting the angle in the first place.

Make sense? Hope so.


It’s because the Mouse location isn’t the same as the game location.
The mouse X and Y is based on the screen size (or the UI coordinates), while the players X and Y is in the game world.

When you move the camera, you need to update where in the mouse is in the game.
To do this, you want the camera X and Y be added to the Mouse X and Y like this:

In the player:


In the Gun:


Oh, that makes sense.

Oh, that makes sense.