I want to have an object that will function as an enemy. When the players object comes within an x number of pixel radius, the object will chase the player. When the player escapes that radius, the object will cease following until the player reenters.
So basically, an enemy has a personal space, and when you invade that personal space, it chases you until you manage to leave it.
How exactly do I do this?
Thanks in advance.
You could use system compare with the distance() expression
System compare distance( enemy.x, enemy.y, player.x, player.y) < x amount
enemy move at angle towards player, or what ever movement your using.
As newt said, you need to compare the distance of the objects. Don't forget to run that compare under For Each Enemy. So basically:
For each Enemy
-> Distance(enemy.X,enemy.Y,player.X,player.Y) < attackdistance
Develop games in your browser. Powerful, performant & highly capable.
Thanks, worked like a charm.
Another (and faster) way is to instead of using the for loop and the system compare, is to use the compare condition in the enemy object. This is just like the system compare, except the comparison is evaluated for each instance of enemy, picking the ones that meet the equation. So then you would use:
-> Distance(.X,.Y,player.X,player.Y) < attackdistance