• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Ai chasing player

A

Abobey

Guest
So I'm trying to create a ai that chases the player when the game starts this is my code
if instance_exists(oEnemy)
{
follow_player = true;
}
if follow_player == true
{
move_towards_point(x,y,sPlayer)
}
 
A

Abobey

Guest
and i also tried if instance_exists(oPlayer) but it didd't work
 
So is this code running in your oEnemy Step Event? Two things, follow_player can never get set to false, which negates the use of the instance_exists, and you're using move_towards_point() completely wrong, look up the function in the manual...You supply the x and y of the position you want to move TO (oPlayer, in this circumstance) and the third argument is the SPEED of movement, yet you've supplied what looks like the player sprite? sPlayer? Here is some code that might function the way you want it to:
Code:
if (instance_exists(oPlayer)) {
  follow_player = true;
}
else {
  follow_player = false;
}

if (follow_player) {
  move_towards_point(oPlayer.x,oPlayer.y,4); // 4 here is the pixels per step the enemy will move, a higher number is faster, a lower number is slower
}
 

Fabseven

Member
I donot know how is your game but move_towards_point might not be enough
try and see if the mob is going through walls or others stuffs you donot want it to go through.
 
Top