| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
collision detection
Hello all,
I am programming a game and I have started to program the movement of the main character, I am using the bitmap mode, I have created a table where I store the position of obstacles. I read this map to check if the sprite is touching a tile or not to the left, right, up and down. I would like to know what approaches do you use or would use in this case. the protagonist should walk and jump over tiles. Is the collision detection from vic any good? |
|
| |
cadaver
Registered: Feb 2002 Posts: 1160 |
I wouldn't rely on VIC collision, it raises hell anyway when you get into sprite multiplexing.
Since I've used character mode I define a collision byte for each char of the background charset, where different bits denote different kinds of scenery/obstacles (for example bit 0 = can walk on).
The chars could be checked either directly from screen memory (faster) or from the level map (slower, but gives possibility of offscreen collision detection).
If you build your bitmap screen from chars or blocks then the latter method, checking from levelmap, could be applicable to you, but if the backgrounds are kind of "freeform" then it doesn't apply..
|
| |
Radiant
Registered: Sep 2004 Posts: 639 |
I'd check the sprite's bounding box against the tile positions, to determine if there's a collision and where. Lacking tiles, I'd go for a similar approach with an invisible collision mask, much like you've done it seems. The VIC's collision detection is better left alone unless you're doing a very simple game. |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
My problem is that this is not working well
the game tiles are 16x16, the actor is also the same size.
when I read the collision map I divide x and y by 8 and this is working or so it seems.
When I created the routine to move the sprite, if going left I check the collision map with x-1 to see if there is a tile there if it is wont move left if it isn't move one pixel left.
this works
my problem is when jumping and checking underneath to see if there is a tile. I check x, y-2 and x+1, y-2 to check if the sprite is hanging in the "air" and make it fall. This cause the problem that when walking on tiles sometimes it falls between tiles or in the middle of a tile or jumps but instead of staying on a tile falls and only stays there if I jump again. I have checked the values from the col map and it seems to be all ok...
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
maybe it would be better to divide with 16 ? |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Quote: maybe it would be better to divide with 16 ?
Can you please elaborate Oswald?
why 16 would work and not 8? |
| |
Hein
Registered: Apr 2004 Posts: 954 |
When I was working on a small game, I used a bottom-center point of the sprite (feet) and checked from there. That point always corresponds to a char on screen (or level), that has bits (or combination of bits) set to see what kind of collision is happening. I wouldn't go for the x+1 method, I'd check from current sprite position. If you want to check for enemy collision as well, you'd need the mentioned invisible mask.
VIC sprite/sprite detection can be used to see if sprites are touching, either to refine the collision with a software detection routine, or skip software collision detection.
Good thing about a single point is that the player can move around, even if it's beween two tiles.
|
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Quote: When I was working on a small game, I used a bottom-center point of the sprite (feet) and checked from there. That point always corresponds to a char on screen (or level), that has bits (or combination of bits) set to see what kind of collision is happening. I wouldn't go for the x+1 method, I'd check from current sprite position. If you want to check for enemy collision as well, you'd need the mentioned invisible mask.
VIC sprite/sprite detection can be used to see if sprites are touching, either to refine the collision with a software detection routine, or skip software collision detection.
Good thing about a single point is that the player can move around, even if it's beween two tiles.
My detection map is 1 byte per char(8pixels x 8pixels ).
0SS
0SS
00TT
00TT
for example the S represents the sprite(2x2 chars) the tile is T the same size. 0 is background
I read for exemple under the bottom left S and get 0 and read under the bottom right one and get T so it means that the sprite is on a tile, should not fall.
The sprite moves 1 pixel a time tho, might change it to two.
I guess your method is different, you read from the screen itself to check, not a col map? |
| |
Hein
Registered: Apr 2004 Posts: 954 |
I used high nybble of colourmem for collision bits, low bits were poked to colourram. (To save memory) You can have a seperate collision map too, if you need more collision combinations. I didnt need more than 16. Timanthes has the option to create a collision map.
I am wondering if it is wrong if the point between your two SS isnt on a tile, thus making the sprite fall. Once a player is used to it, he will consider it while playing.
Personally, I like platformers that leave some space for making miss-movements. Too tight detection can be quite frustrating.
considering your x+1 or y+2 movements: you gotta be sure to have a flexible movement speed of the sprite. When a sprite falls, gravity takes over, possibly this is y=y+3, what do you do then? |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
algarby, just a fast idea, since your tiles are 16x16, then a collision map is 1/16th of the sprite coordinate resolution and not 1/8th. |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Oswald but some tiles can be moved and they can be moved in one byte steps. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
well allright then. you got your algorythm wrong. try a troughout testing with nailing the problem down to extremely simplistic situations. |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
It is working now, it was a tiny bug but that made me think that the collision detection routine was wrong, I was not updating one variable somewhere :S grrr thank you guys for the help |