cdx sprite tile collision
Hi I have some problems with cdx collision detection between sprites and tiles, does someone know how it works? For example my main character sprite is 128x141 and my tiles are 32x32, but collisions only work sometimes..it''s very strange.. must the sprites have the same dimensions as the tiles or something? Please help!!!
Are you just checking for the collision with the surface of the tile or the entire tile? Maybe the problem is that your character is falling too fast to actually be hitting the surface of the tile.
Just check these and that should fix your problem
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Just check these and that should fix your problem
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
I don't think the sprite falling to fast is the problem, even when it's standing still the collision sometime don't work..I don't understand the code that cdx uses for collision detection..
here is the code from cdx:
does someone know if this code can detect collision between a 128x141 sprite and 32x32 tiles ?
Edited by - Cafall on August 15, 2000 8:36:22 AM
here is the code from cdx:
//////////////////////////////////////////////////////////////////////////////////// Checks for collisions between the source sprite and tiles in a map. Returns // TRUE if any part of the sprite overlaps with a tile of value Tile in the specified map.// In mMap->GetTile(x,y) it's necessary to keep within the X and Y boundaries!// So min(X,MaxX-1) ensures that you can't exceed the max X or Y position//////////////////////////////////////////////////////////////////////////////////BOOL CDXSprite::TileHit(CDXMap* pMap, int Tile){ int MapX, MapY, TileType; // Check top left MapX = (pMap->m_PosX + m_PosX) / pMap->m_TileWidth; MapY = (pMap->m_PosY + m_PosY) / pMap->m_TileHeight; TileType = pMap->GetTile(min(MapX, pMap->m_Width-1), min(MapY, pMap->m_Height-1)); if(TileType == Tile) return TRUE; // Check top right MapX = (pMap->m_PosX + m_PosX + m_Tile->m_BlockWidth) / pMap->m_TileWidth; MapY = (pMap->m_PosY + m_PosY) / pMap->m_TileHeight; TileType = pMap->GetTile(min(MapX, pMap->m_Width-1), min(MapY, pMap->m_Height-1)); if(TileType == Tile) return TRUE; // Check bottom left MapX = (pMap->m_PosX + m_PosX) / pMap->m_TileWidth; MapY = (pMap->m_PosY + m_PosY + m_Tile->m_BlockHeight) / pMap->m_TileHeight; TileType = pMap->GetTile(min(MapX, pMap->m_Width-1), min(MapY, pMap->m_Height-1)); if(TileType == Tile) return TRUE; // Check bottom right MapX = (pMap->m_PosX + m_PosX + m_Tile->m_BlockWidth) / pMap->m_TileWidth; MapY = (pMap->m_PosY + m_PosY + m_Tile->m_BlockHeight) / pMap->m_TileHeight; TileType = pMap->GetTile(min(MapX, pMap->m_Width-1), min(MapY, pMap->m_Height-1)); if(TileType == Tile) return TRUE; return FALSE;}
does someone know if this code can detect collision between a 128x141 sprite and 32x32 tiles ?
Edited by - Cafall on August 15, 2000 8:36:22 AM
Your code looks like jargon to me.. too late at night I guess...
Shouldn't it be:
If falling through tile then put character on top of tile.. instead of all that division? If...then should be the solution, I just can't figure out where
Hmmm, I see what it is trying to do, but the divisions are just too much for me... Damnit.. I had best get some sleep
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet
Edited by - dwarfsoft on August 15, 2000 8:40:07 AM
Shouldn't it be:
If falling through tile then put character on top of tile.. instead of all that division? If...then should be the solution, I just can't figure out where
Hmmm, I see what it is trying to do, but the divisions are just too much for me... Damnit.. I had best get some sleep
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet
Edited by - dwarfsoft on August 15, 2000 8:40:07 AM
Yes I don''t understand the code either.. here is how i use it in my game:
if(Sprite->TileHit(Map, TileNumber) == TRUE))
{
// collision!!
}
but that only detects collsions sometimes.. sometime i can move the sprite right on top of a tile...but no collision....
if(Sprite->TileHit(Map, TileNumber) == TRUE))
{
// collision!!
}
but that only detects collsions sometimes.. sometime i can move the sprite right on top of a tile...but no collision....
I see it like this instead for hitting the tile:
Do you understand this? I think it is a lot simpler personally
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Hit=true;if ((Bottom_of_sprite > top_of_tile) || (Top_of_sprite < bottom_of_tile)){ Hit=false;} else{ // figure out which way to bounce it}if ((Left_of_sprite > right_of_tile) || (Right_of_sprite < Left_of_tile)){ Hit=false;} else{ // figure out which way to bounce it}...if (Hit){ // Bounce it this way, based on the two comparisons..}
Do you understand this? I think it is a lot simpler personally
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Yes that seems a bit clearer, but how would i get the top_of_tile
and bottom of tile coordinats? I can use Map->GetTile(x, y) to get the tile number but not the tile x and y...?
and bottom of tile coordinats? I can use Map->GetTile(x, y) to get the tile number but not the tile x and y...?
I think (I am having a guess) that you can get the tile coordinates like so:
with a map that has the tile(x,y) as:
(maxheight,0) -> (maxheight,maxwidth)
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|b|
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
|a|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
(0,0) -> (0, maxwidth)
where a = (0,0) and b = (maxheight,maxwidth)
Does that make sense?
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet
Edited by - dwarfsoft on August 15, 2000 9:10:06 AM
with a map that has the tile(x,y) as:
(maxheight,0) -> (maxheight,maxwidth)
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|b|
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
|a|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
(0,0) -> (0, maxwidth)
where a = (0,0) and b = (maxheight,maxwidth)
Top_of_Tile = (x+1)*Tile_Height;Bottom_of_Tile = (x)*Tile_Height;Right_of_Tile = (y+1)*Tile_Width;Left_of_Tile = (y)*Tile_Width
Does that make sense?
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet
Edited by - dwarfsoft on August 15, 2000 9:10:06 AM
August 15, 2000 08:20 AM
Should''nt you be detecting collision with the sprites pos, instead of the tiles?
It should check to see if the sprite for the character enters into a tile... that is simple collision, and it is FAST!
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement