HELP please I NEED help

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

3 Likes

credit to @alexk

2 Likes

You can use Browser Events to do that!

1 Like

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:

4 Likes

Sure @adicat , you can use the Browser Events Extension to do achieve this!

Here is an example:

since I’m on mobile, when I click the bullet goes to the last place I clicked, resulting in this:

1 Like

Yeah thats a browser events bug, it kinda just happens…

1 Like

no, it’s an update bug. The left click block updates before the on mouse move does and that’s the problem.

1 Like