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

2018/6/28

Collision Detection From Different Sides

Vise Vise

2018/6/28

#
Let's say I have a rectangular block. How would I determine if another actor is touching the top of the block or the bottom of the block or side of the block. Is it possible in greenfoot? If so, what is the general idea to do so and the methods needed for it? Thanks.
danpost danpost

2018/6/29

#
Vise wrote...
Let's say I have a rectangular block. How would I determine if another actor is touching the top of the block or the bottom of the block or side of the block. Is it possible in greenfoot? If so, what is the general idea to do so and the methods needed for it?
The way I would handle it is by separating horizontal movement from vertical movement and using the direction of movement of each to determine how contact with an obstacle was achieved, allowing for the reversion or proper location setting upon such contact. The idea can be seen in the code of the Who class of my Jump and Run Demo w/Moving Platform scenario. Just run the scenario on this site and click the Who button along the bottom of the window to view the codes.
You need to login to post a reply.