Is there a way to detect whether I am moving towards a particular entity or if I am moving towards a particular entity type?
The issue I am having is to check whether I have hit a fence. At that point I want to turn around and move in the other direction. However, the collision is still happening so I can never auto move.
So I need to know if I am heading towards the fence or away from it.
I have tried this but unless I loop through all my fences I can't detect.
if (this.distanceTo(EntityRobotFence)< 50) this.stopMoving();
This doesn't work btw.
Have you tried using the following:
var target = ig.game.getEntitiesByType(EntityRobotFence); // or (EntityRobotFence)[0], etcthen:
if (this.distanceTo(target) < 50) this.stopMoving();NOTE:
this.distanceTo()returns the absolute distance in pixels from this entity's center to the other entity's center. So ensure your pixel distance is correct.