Gw Temp
Menu
Tutorial - 'Mousing Aiming, And Basic AI' by Guest
An item about Gamemaker posted on
Blurb
Need to know how to use that mouse to aim in Game Maker? Read up, son!
Body
ifficulty:1/5
Requirements:Variable knowledge/some GML
Ok,first off,the aiming with mouse.Make the sprite of a crosshair or whatever.make sure to set the origin to the middle(You need to be in advanced mode)now,make a new object.Have it be the sprite for the crosshair you made.Now,in the step event,put this.
x=mouse_x
y=mouse_y
So it should be at the mouse.Go under game options now.Set it so the mouse isnt displayed.Now,make a bullet.In the create event for the object,put this.
move_towards_point(mouse_x,mouse_y,8)
Now,it's all set.except for one thing.Make a new object.Now,make a global mouse pressed event.in it,put this.
instance_create(player.x,player.y,bullet)
and voila!
AI
Ok,this is simple.put this in the stpe event for the object.
if distance_to_object(player)<200 {move_towards_point(player.x,player.y,8)}
Easy.Now,if you want it to chase and fire bullets...
make an enemy bullet object.put this in the create event for it.
move_towards_point(player.x,player.y,8)
and in the collision event,have it do damage then destroy itself.now,in the actual enemy,set variable shoot to 1 in the create event.now,put this in the stpe event.
if distance_to_object(player)<200 {move_towards_point(player.x,player.y,8) if shoot = 1 {instance_create(x+0,y+0,enemybullet) shoot = 0 alarm[0] = 3}}
now,in the alarm 0 event,set shoot to one.and there you have it,aiming with mouse and some basic AI.
Please tell me of any bugs,
-Tehdude