I am making a game and I want the player to be able to move their mouse around and when they click, a projectile goes towards the direction of where you clicked. please help
credit to @alexk
You can use Browser Events to do that!
You gotta use the browser events extension combined with Sprite utils. Browser events is in the default list, sprite utils is:
jwunderl/arcade-sprite-util
Then, you should have your player sprite working already. Now, create a crosshair sprite to follow the mouse cursor’s position. Add this chunk of code:
This makes it so the crosshair follows the cursor, accounting for how much the camera scrolls (i did not figure this out myself i took it from @WoofWoof )
Now, to make shooting, add a “on left mouse button pressed” block, and create the bullet from there. You can follow this example:
The “velocity at angle” block is why we need Sprite Utils.
Here’s the project containing my example code:
Sure @adicat , you can use the Browser Events Extension to do achieve this!
Here is an example:
Yeah thats a browser events bug, it kinda just happens…
no, it’s an update bug. The left click block updates before the on mouse move does and that’s the problem.


