Search code examples
game-maker

How would I be able to use my mouse to shoot


So far I've created an object called obj_mouse. And my plan is whenever the player left clicks, it spawns a bullet from him toward where ever the mouse is pointing. I've got the concept down, but I'm struggling getting it to work.

Extra bits of code I'm messing around with to try to get it to work:

bullet=instance_create(x,y,obj_bullet)
with (bullet) {
     move_towards_point(mouse_x,mouse_y,5)
     image_angle=direction
}

point_direction(obj_mouse,obj_mouse,obj_mouse,obj_mouse)
image_angle=direction

(In the above code, I have not attempted to specify to the program that I want the bullet to go in the direction of obj_mouse, or rather, just the mouse. The above code works, and bullets do shoot, however the player must have the mouse on the players sprite for it to work.)

Thank you in advance for any advice given.


Solution

  • The fix was applying the piece of code to a global mouse click event, so that it does not call the code from the object being left clicked rather it calls the code when left click is clicked.