Tips on collision Detection

PurulentSoftwarePurulentSoftware Member Posts: 15
edited November -1 in Working with GS (Mac)
Anyone know a better way of doing collision detection because a box doesn't work very well for game characters and animations.

Comments

  • QuinnZoneStudiosQuinnZoneStudios Member Posts: 452
    Good question.
    I wonder if you could make shapes out of a series of rectangles and spheres and constrain them together to make the desired collision shape? That's basically all they do in AAA titles anyway.
    Might be worth an experiment.
  • ckurt25ckurt25 Member Posts: 122
    I'm going to have to give that a shot because the detection is WAY off.

    In a game I'm working on now I have a small ball that is set to collide with different objects and then destroy itself if it hits certain objects. I also have a collision rule to collide with itself. If I "shoot" one ball off in say a nice slow high arch and then another after it in a fast straight line and the 2nd one collides with the 1st, they are about 3-4 times their own width away from each other when they collide. Visually, that looks like crap and that scenario could very well happen in my game.

    I guess I'll try creating a hit area that's actually a clear image whose X & Y position is (I guess) constrained to the X & Y position of the ball and whose size is considerably smaller and play around until I get a more visually realistic result.

    AFTER FURTHER REVIEW--- ID Ten T Error

    I had the size of the ball wrong in the actors size attributes. Loaded a new image and have the correct size and it works correctly. Oops.
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    Here is what i do.
    It is two fold. Detects better and dramatically increases performance.

    1. The first part is nothing new just use invisible actors as collisions.
    Its easier than it sounds . You make little squares and name them something like col1, col2, col3. Your actor will then spawn them. If the actor is static its really easy because you dont need to constrain anything.

    If it moves pull the collisions actors over to y our field and make them visible. Rotate them around until you parts of the square poke out where you need.
    No matter what size you make the collision point if you can make the middle of it cross the middle of your actor you can constrain it or them to your actor. I lay every thing in a blank field so i can do everything over the little x. Its not scientific but for me i prefer visual.

    2. If you are just using a non scrolling screen and have lots of non moving actors just make one background image with all of them rather than seperate actors all with collision fields. You can then place invisible actors all over you back ground image.

    From testing i can tell you that one 480x320 image and 20 actors with no image at all performs better than 20 actors with a 128x128 image all out at the same time.

    This cuts back on performance and size an in turn saves loading time.
  • ckurt25ckurt25 Member Posts: 122
    Now I've run into an odd problem. My actor that I'm trying to use a collision area for has an odd shape. Other actors fall on its head and without a collision area if the actors fall right, they'll look like they should be tipping over the edge when they aren't. So I'm trying to create this collision area that is basically the width of the characters head. Everything checks out so far. When I place it in my scene and drop it anywhere, the collision behavior works. When I do the constrain self.position.x to game.myactorx the constraint works but then collisions stop working. I'm scratching my head on this one. I'm sure it's something very simple but it hasn't dawned on me yet.
  • ORBZORBZ Member Posts: 1,304
    I use a collision circle/box slightly smaller than my player and constrain that to the x,y of the player's visual actor.
  • ckurt25ckurt25 Member Posts: 122
    It doesn't matter how big or small the collision box is for me. If I use constrain attribute, nothing will collide with it. ARGGHHH!
  • ckurt25ckurt25 Member Posts: 122
    Actually something even more weird is happening. I'm sure its me but I can't figure it out. Think of a 3x3 grid and numeric values for each spot in the grid

    1 2 3
    4 5 6
    7 8 9

    I originally drop the collision actor in the scene say in space #3 and my actor that I'm constraining it's position to is in spot #8. When I hit preview, it appears to now be in space 8 like it should be, but the collisions are occurring like it's still in #3. I took a 2 hour break and now think I need to find some green beer.
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    may sound silly but are you making sure you have your "constrained" collisions visable for testing?

    just makes it better to not miss something easy.
  • ckurt25ckurt25 Member Posts: 122
    Yeah, I did. That's how I knew it was moving from spot 3 to spot 8.

    I actually gave up. Its not that big of a deal as the actor doesn't move until the very end of the level and by that time, there won't be any more collisions. It's just weird though. Since I'm probably going to have roughly 40 to 50 levels by the time the game is ready for release I was hoping I could just do it quick and dirty. Now I'll just have to make sure the collision actor is placed exactly where I need it. I guess all in all, it'll add just a few minutes over a few weeks of total development time. I've probably spent more time posting in this thread then it'll take to drop the actor exactly where it needs to go in 40 or 50 levels.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I'm pretty sure that a constrained actor will obey the constrain before it obeys any collisions...

    So if, for example, you have an object constrained to the mouse, it will stay constrained to the mouse even if you drag it through walls, etc.
Sign In or Register to comment.