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

2014/3/7

Greenfoot collision with actors

Mitchr101 Mitchr101

2014/3/7

#
Hi, I have created a Greenfoot scenario and I am attempting to add collision code so that my actor characters cannot exit the map via the walls. The wall on the very left is the only wall I have added as a class file under actors, and I have provided an image. Any ideas on how to accomplish this?
davmac davmac

2014/3/7

#
After movement, check for collision with the wall, and if you detect it, restore the location from before movement occurred.
danpost danpost

2014/3/7

#
There are several different methods that are provided for collision detection within the Actor class. Look through the API documentation for possibilities for your use. Usually, the sequence of operations taken is (1) move (2) check intersection (3) if intersecting, move back or back off.
Super_Hippo Super_Hippo

2014/3/7

#
Interesting, I always check first whether or not it would intersect and give (or do not give) the permission to move.
You need to login to post a reply.