Inacurrate Aiming

When you make a game and you aim using the mouse, sometimes it doesn’t go where it is supposed to.
https://flowlab.io/html5/bin/1320892
Is the game.

Anyone?

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.

-Kollama

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:

2020.01.10-20.46

In the Gun:

2020.01.10-20.45

Oh, that makes sense.

Oh, that makes sense.