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

2012/12/29

Collision Detection Problem

MrBunni MrBunni

2012/12/29

#
Hi, I've been programming a game involving a helicopter saving people, but I've run into a problem. As you can see in the picture, the helicopter crashes when it looks like it doesn't touch anything, but it touches the transparent background of the picture. In the helicopter class I've been using the getOneIntersectionObject(name.class) to detect collision:
Actor Drooggebied = getOneIntersectingObject(Drooggebied.class);  
 if (Drooggebied != null){
                super.exploded = true;
     }
Is there a better way of detecting collision? I've already tried cutting away the transparent background in Photoshop, but that is sadly not possible. I thought of a very time consuming solution, which is no longer using the pictures as the check for Intersection, but creating a new Actor with small squares, which are placed behind the pictures and are used to detect collision. But this is hopefully not necessary, since I don't have that much time. Thanks in advance!
Kyle273 Kyle273

2012/12/29

#
Unfortunately, pixel perfect collision detection is pretty tricky. I'd recommend some of the following: 1: Creating a "ModularSizeTerrain" Class, basically a square that you can change the size of. Take a look at the GreenfootImage documentation. 2: Create more actors. whenever there's a change in height in your terrain picture, split it. For example, you could have a "Hill" actor, and a "Flat" actor. It'd make it easier to build and change levels as you were testing your game as well. remember, you don't want to have to redraw your whole level every time you want to make a change. If you're relatively new to programming, I'd suggest sticking with square collision detection.
MatheMagician MatheMagician

2012/12/29

#
You could draw on the world background and then use the getWorld.getColorAt(x,y).getGreen(); method to check whether you hit a hill.
MrBunni MrBunni

2012/12/30

#
Thanks for all the suggestions, I'll go with splitting height in images since I can implement that fairly easy but is still quite good.
You need to login to post a reply.