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

2012/5/9

My Collision detection isn't right

dlanni dlanni

2012/5/9

#
In a room, a woman can access other levels by going thru doorways. Unfortunetly, she can also walk thru the walls. I made the walls a class(Walls) and they are a physically diff Object. /* * I want this to work only when her midpoint y = y + (getheight/2) * In other words, only when bottom(feet)intersect Walls. */ public boolean canSee(Class clss) { Actor actor = getOneIntersectingObject( clss); return actor != null; } //The keypress controls are here, so she can only move if she isn't climbing walls. public void checkForWalls() { if(!canSee (Walls.class)) { checkKeyPress();} } I will post the scenario with open code so you can see what I'm trying to do. Thanks in advance for your guidance.
davmac davmac

2012/5/9

#
The collision checking isn't that sophisticated - it doesn't take the shape of your image into account, only the rectangular shape of the actor. So in your scenario, the woman is always colliding with the wall. You could use smaller actors - "pieces" of wall - and this might get you a bit further. Or, you could try to detect collision based on co-ordinates rather than checking for actor collision - though this is more complicated to implement!
dlanni dlanni

2012/5/9

#
What if I cut out the shape of the exposed carpet and do a -- if feet are not on solid ground, don't allow movement
dlanni dlanni

2012/5/9

#
I will be figuring contact point as x, y - 1/2 of height. Will that work, or will she get stuck off the carpet and not be able to move at all?
dlanni dlanni

2012/5/9

#
Maybe it would be simpler (and good practice) to make a map array like the maze and platform games. I just thought this would be easier and more accurate.
davmac davmac

2012/5/9

#
What if I cut out the shape of the exposed carpet and do a -- if feet are not on solid ground, don't allow movement
You could do that, but, like I said, Greenfoot won't take the shape of the image into account - only the rectangular actor shape. It might still be enough for your purposes.
I will be figuring contact point as x, y - 1/2 of height. Will that work, or will she get stuck off the carpet and not be able to move at all?
I think you'd want (x, y + 1/2 of height), if you're looking for the carpet. You have to make sure it's not possible to move off the carpet so you don't get into a situation where you can't move at all.
Maybe it would be simpler (and good practice) to make a map array like the maze and platform games.
Yep, that could work.
dlanni dlanni

2012/5/9

#
Thanks.
You need to login to post a reply.