I have my Enemy actor set to move left and when it hit's a certain actor named "invisibleBarrier" it stops. I would like to make it so that it makes the Enemy actor move the other direction and when hitting another actor which I named "invisibleBarrierRight", it changes direction again and repeats that process as a patrol route. I found this code from another user requesting help but it didn't seem to work out how I was hoping. Here is my code:
public void act() { patrolArea(); steps = (steps+1)%300; } private void patrolArea() { if(getObjectsInRange(20, invisibleBarrier.class).isEmpty()) { if (steps == 0) speed = -speed; move(speed); } }