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

2015/10/1

Giving actors collisions and bounds?

oscarreks oscarreks

2015/10/1

#
I have a scenario which has the player in the middle of the screen who can move around the map, and enemies that move towards the player. The enemies don't have collisions or anything yet, so they always end up bunching together when the player kites around them. How do I add "collisions" and "bounds" to the enemy so they don't overlap each other? btw, the enemies move by turning towards the player and then moving forwards with the move() method. I have a feeling that adding collisions will be too complex for this simple movement system.
davmac davmac

2015/10/2

#
You can check for collisions with another enemy in the same way you check for collision with a player (or, from the player, that you check for collision with an enemy). (Use, for example, getOneIntersectingObject()). To prevent enemies from occupying the same space, the simplest solution is to check for a collision immediately after moving, and revert the movement (move backwards) if there is a collision. You might find this leads to two actors getting "stuck" against each other. If you get that far, post again and we can discuss how to solve that.
You need to login to post a reply.