• 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!

Checking if an object is moving away from a point?

C

cheezy_squeezy

Guest
Hi all, basically just making some enemy AI that goes to the player's last known position after they have broken line of sight behind a wall (top down game).

It all works fine apart from the enemy not stopping after it has started walking past the player's last known location. I thought this check would work (let playerx and playery be the co-ordinates for their last known location):

if point_distance(xprevious, yprevious, playerx, playery) < point_distance(x, y, playerx, playery) (stop);

My thought process is that when the enemy starts increasing its distance from the coordinates rather than decreasing it (moving away from it) it would stop, but it doesn't seem to have an effect. Am I misunderstanding something here? Cheers.
 

FrostyCat

Redemption Seeker
xprevious and yprevious can only be used to detect position changes on or after the End Step event.
 
C

cheezy_squeezy

Guest
xprevious and yprevious can only be used to detect position changes on or after the End Step event.
Oh ok thanks. Any idea what I could do then? I'm sure you figured that that line was in the step event.
 

FrostyCat

Redemption Seeker
Oh ok thanks. Any idea what I could do then? I'm sure you figured that that line was in the step event.
If a restaurant advertises "dinner will be served at or after 7PM" and you want dinner there, your solution would be to come at 7PM.

I said xprevious and yprevious can be used to detect position changes on or after the End Step event. Your solution would be to move that piece of code to the End Step event.
 
C

cheezy_squeezy

Guest
If a restaurant advertises "dinner will be served at or after 7PM" and you want dinner there, your solution would be to come at 7PM.

I said xprevious and yprevious can be used to detect position changes on or after the End Step event. Your solution would be to move that piece of code to the End Step event.
Oh ok sorry, thanks.
 
Top