Hey, so I'm doing a project in class, and I want an enemy to follow an Actor. If someone could give me code to use or a game that has this, plz show or tell me ASAP!


1 2 3 | public int getX(){ return xPos; } |
1 2 3 4 5 6 7 8 9 10 11 | //all this happens in enemy class //xPos = the actual position of the enemy //speed = the speed of the enemy private void followActor(){ if (xPos < actor.getX()){ xPos = xPos + speed; } else if (xPos > actor.getX()){ xPos = xPos - speed; } } |
1 2 3 | public int getX(){ return xPos; } |