Which type of Game maker do you use?

Saturday, March 15, 2014

How To Shoot Toward The Mouse

Hello friendly game maker fellows! I was making a game a bit ago where you use w,a,s,d to move and the mouse to shoot. Then i thought "Hey, I should put a tutorial on how to shoot the mouse." And here I am.

Alright so the first thing you want to do is make 2 sprites, obj_guy & obj_bullet.
Now go to the obj_guy and select the event Global left pressed. (mouse->Global mouse->Global left pressed)
once you've done that go to execute code (under controls tab) Don't stop reading because there is coding it is at most 5 lines.
Type in:

with instance_create(x,y,obj_bullet)
{
speed=20
direction=point_direction(x, y, mouse_x, mouse_y)
}

This code is saying to create instance of obj_bullet with the speed of 20 and the direction is where mouse was clicked.

That's how to shoot toward the mouse.

Another thing you might want in to make your character look at the mouse. this requires coding but only 1 line.
So under obj_guy click the step event.
Then click execute code.
Type:

image_angle = point_direction(x,y,mouse_x,mouse_y);


This is telling gamemaker to make obj_guy follow the direction of the x and y of the mouse.

That's all you need required to make multiple other types of games.
Thanks for reading.
Happy Gaming!

No comments:

Post a Comment