![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
Collision Detection in 'Worms' |
blargmob
Member #8,356
February 2007
![]() |
We've all played the game 'Worms' or 'Worms: Armageddon' at one point. How is the collision detection done in that? With all the curves and even custom maps, how do they check and handle collision detection? --- |
Albin Engström
Member #8,110
December 2006
![]() |
using pixels! this is the ultimate classic effect!.. and it's very easy to acheve. to make it simple: you have a bitmap representing the map or playfield or whatever you want to call it.. then you just check the Yposition+1 of the player using if(getpixel(map, x, y) != (255,0,255)) to check for ground collision, for the x in worms they just checked if the wall the worm was walking against was low enough for the worm to clim (4 pixels or something) and stopped it there, they didn't alter the speed by checking if the worm was walking up or down hills but you can if you want. the best thing about using this approach is that you can easily edit the map during play with for example explosions and such! Like i said, in worms(2) the collision detection was VERY simple. but if you want to make it more advanced nothing is stopping you except some work you have to overcome |
kazzmir
Member #1,786
December 2001
![]() |
Probably split the map into smallish squares, 64x64 or so, and every time an object moves check its pixel mask against the current square. Since there aren't a ton of moving objects in the game at any one point this should work fairly well and scales to arbitrary map sizes. |
Albin Engström
Member #8,110
December 2006
![]() |
I don't recommend checking with pmasks.. using one or two points for the collision detection is much easier and works much smoother. i remember someone posting an example of some advanced pmask routines, really cool except it wasn't! it was just unnecessary and flawed. Trust me.. use one point for ground detection, one for over head, and use those two together against walls. pmasking isn't worth it.. try animating something and use pmask.. |
blargmob
Member #8,356
February 2007
![]() |
Sorry, but what's pmasking? --- |
Albin Engström
Member #8,110
December 2006
![]() |
I'm not 100% sure, but i think it is when you have two bitmaps and check if the pixels which aren't transparent overlaps. If you think about it.. it sucks. |
kazzmir
Member #1,786
December 2001
![]() |
Have you ever used pmask? It doesn't sound like you have. If you aren't doing that much checking then testing a 16x16 sprite vs a 64x64 square isn't that bad at all. pmask is pretty fast. |
Albin Engström
Member #8,110
December 2006
![]() |
yeah, but lets say your animating a character which runs up a hill.. and how would we even use pmask to make this whole process smooth and painless? i can't name one good sidescroller which uses pmasking.. in fact i can't even name a game that uses pmasking.. except from some i made with games factory (ashamed) when i was little. Sure, i would gladly think that it sucks because it think it sucks because my memory tells me it sucks... but no matter how i think about practical use of pmasking i can't make good use of it (sorry for making this thread into a little discussion) If you need any help regarding the collision detection just post it here and i'll try to help, if that's what you want of course.. |
blargmob
Member #8,356
February 2007
![]() |
Sweet thanks for help.. --- |
kazzmir
Member #1,786
December 2001
![]() |
Quote: yeah, but lets say your animating a character which runs up a hill.. Worms/worms armageddon consists of more than just hills... there are arbitrary sets of pixels floating about the map. How are you going to deal with that? |
Albin Engström
Member #8,110
December 2006
![]() |
you don't.. the checking around the point is enough to stop the worm if it's hitting those little pixels. using the same checking routines as you do for the walls.. ok.. i call it one point but you check points around it, so it's kinda like pmask except the sprite doesn't effect the game and a million of unnecessary pixels isn't checked which you would have to deal with in some horrible ways too. |
StevenVI
Member #562
July 2000
![]() |
I suggest you try my game Lander and tell me that your idea is better. The pixel checking worked at an excellent speed on the 486 I originally wrote the game on. I'm not sure if I'm just misunderstanding you. Is your entire argument that checking the pixels for overlaps is okay so long as you don't check the entire map at once? If this is so, then we are in agreement. You only need to check the pixels in the vicinity of the sprite you are checking for collisions with. __________________________________________________ |
Albin Engström
Member #8,110
December 2006
![]() |
I only played the windows version (which seemed to be different) and all i have to say is: ok, good example of a game that has uses for pmask, but for a platformer like worms or castlevania or super mario, i don't think pmask is the right decision. i mean.. sure, pmask has it's uses.. but seriusly.. animation + pmask.. i just can't get those two together. btw, i could not control the spacecraft
|
StevenVI
Member #562
July 2000
![]() |
Yikes. I have no idea what's wrong with that. I must have put an older binary online by mistake. I'd check it but I'm not in Windows right now. __________________________________________________ |
Tobias Dammers
Member #2,604
August 2002
![]() |
IIRC, worms doesn't really do a bitmap <-> bitmap check, but rather just a pixel <-> pixel check. The projectiles just check the pixels they go through, and the characters to the same thing with a pixel at the center of their baseline. pmasking won't really work, since you'd basically have to recalculate the masks each time the terrain changes. OTOH, the terrain only changes once per move, and never while any movement occurs, so it might still be a good idea. For those who don't know how pmasking works: --- |
Thomas Harte
Member #33
April 2000
![]() |
Quote: Like i said, in worms(2) the collision detection was VERY simple. It was more complicated than you think in some ways, at least in Worms 2 onwards. Check out the way the Ninja Rope bends around the landscape. Quote: you have two bitmaps and check if the pixels which aren't transparent overlaps. If you think about it.. it sucks. If I think about it then: it registers an overlap exactly when the player sees an overlap. Quote: t would be great if some of the big guys would name ONE use of pmasking that one point checking can't do a million times better. I don't think I qualify as a big guy, but how about bullets in a shoot'em'up? Or just about anything on a high resolution screen? There's no way a pixel sized spot is going to cover much of a sprite. Quote: i can't name one good sidescroller which uses pmasking.. I think that might be more because most games don't declare the nature of their collision detection routines. If it helps the argument at all, all the console systems that follow the Texas Instruments TMS9918 line have the functional equivalent of pmask collision detection in hardware — every pixel overlap between sprites flags up as a collision. That means that you've almost certainly played side-scrollers with something the same as pmasking if you've ever played one on a Colecovision, Master System or Mega Drive. The Lynx also has equivalent functionality though it costs 8 kb of the total 64 kb RAM so may not be used so pervasively. Based on the hardware, I think most 8bit platform games (i.e. the ones with an obviously grid based map) use a simple grid fitting collision detection for player/map collisions and a proper pixel check for player/shot/enemy collision detection. [My site] [Tetrominoes] |
Audric
Member #907
January 2001
|
I'd go for a check of the bounding box of moving things (worms, mines, projectiles) vs the pixel mask of the landscape. |
Albin Engström
Member #8,110
December 2006
![]() |
Thomas Harte said: It was more complicated than you think in some ways, at least in Worms 2 onwards. Check out the way the Ninja Rope bends around the landscape. I was thinking more about the worms but ok Thomas Harte said: If I think about it then: it registers an overlap exactly when the player sees an overlap. And that's exactly why i think it's bad :/. Quote: I don't think I qualify as a big guy, but how about bullets in a shoot'em'up? Or just about anything on a high resolution screen? There's no way a pixel sized spot is going to cover much of a sprite. Ok, for non animating sprites pmask can be very effective, although i think pmasking the projectiles in shoot'em'up is more of a design decision that anything else, i like the way the projectile overlaps the enemy by one pixel before it collides. and aren't big enough to make point based collision detection irritating. and if you're using higher resolution you probably don't go with pixel collision detection anyway. Quote: I think that might be more because most games don't declare the nature of their collision detection routines. Hmm, that may be, but shouldn't pmasking be easy to spot? it's quite different to using one point or a box for collision detection. |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: Hmm, that may be, but shouldn't pmasking be easy to spot? it's quite different to using one point or a box for collision detection.
Yes and no. Sure pmask is a lot more precise than a simple bounding box or bounding sphere, but there are other pixel-perfect (or near pixel perfect) algorithms: --- |
blargmob
Member #8,356
February 2007
![]() |
So how do they calculate the angle/surface normal of the surface in Worms? Like when 'nades and worms bounce off realistically.. --- |
Albin Engström
Member #8,110
December 2006
![]() |
I don't know exactly how they did it, but they probably checked for collision and if it's colliding they check the surrounding area and determine the(i don't know what it's called so we will just call it reflection plane..) example: P is the projectile, check the pixel that it's traveling to, if speed > 0 check posX+1 for example(i will call this Xpositive), in this case it going right down at that 45degree hill(we call it 45degree hill.. from where to count the angles ins't th eproblem right now), lets say the speed is Xnegative and Ypositive (in allegro Ypositive is not up it's down.. this gets really confusing when you switch to openGL) the reflection plane could be calculated like this(this is after we have confirmed a collision): since the collision point is Xnegative and Ypositive we should now check Xnegative (by itself) and Ypositive(by itself) and in this case we se that they are solid, this means that the original reflection plane stays as it is(45degrees), then check Xpositive and Ynegative, they're not solid, so it's still 45degrees.. then check Xpostitive&Ypostive vs Xnegative&Ynegative and they're also non-solid.. so where still at 45degrees.. (what i crappy example.. since i don't get to the point of what happens when two corresponding pixels are different..) I hoped you could figure that out yourself but since you asked you probably don't.. and then just reflect the angle and slow down the grenade or whatever. If you're still interested after this shitty and last post of help I'm going to give for the rest of the year(or so i say) i could make an example game for you.(maybe) |
blargmob
Member #8,356
February 2007
![]() |
What? --- |
Albin Engström
Member #8,110
December 2006
![]() |
yeah, figured that much.. |
blargmob
Member #8,356
February 2007
![]() |
So does anybody have a good explanation of angle/surface normal detection in 'Womrs'? --- |
StevenVI
Member #562
July 2000
![]() |
The simple version: look a few pixels to the left, look a few pixels (or just one pixel) to the right. Determine the height of the local area for the given x value. Use the pre-algebra slope formula I feel like I plug my (poopy) games too often. In my game Zonic the Hog, I do something similar to this to determine the slope of the ground, so that I can draw the pig at an angle so he looks like he is actually running along the ground. __________________________________________________ |
|
1
2
|