This site requires JavaScript, please enable it in your browser!
Greenfoot back
VOiDBABY
VOiDBABY wrote ...

2023/5/10

Moving an actor towards another without rotating

VOiDBABY VOiDBABY

2023/5/10

#
I'm creating a 2D game in which enemies on the right side chase after the player on the left side. I was wondering if there's another way for the enemies to chase after the player as they move without rotating as it flips the images (has animations) upside down and backwards. I'd appreciate any suggestions or feedback! Here's my current code:
public void aggro()
    {
         Player player = (Player)getWorld().getObjects(Player.class).get(0);
         int PlayerX = player.getX();
         int PlayerY = player.getY();
         turnTowards(PlayerX,PlayerY);
         move(2);
    }
danpost danpost

2023/5/10

#
VOiDBABY wrote...
I'm creating a 2D game in which enemies on the right side chase after the player on the left side. I was wondering if there's another way for the enemies to chase after the player as they move without rotating as it flips the images (has animations) upside down and backwards. I'd appreciate any suggestions or feedback! Here's my current code: << Code Omitted >>
Just reset the rotation back to zero after moving:
move(2); // line 7
setRotation(0);
You need to login to post a reply.