2d map collision detection

Started by
1 comment, last by karmacop 23 years, 8 months ago
hi my game uses an object table to animate the player and monsters by using x and y velocity variables (including other things, like acceleration and terminal vel.) anyway, the tilemap is made up of 8x8-sized blocks. i want to be able to detect the collision of any object''s hitbox (of any size) on the blocks of the map, and have the objects automatically "pushed out" of the blocks. how is this done with large hitboxes? (like 16x16 or any other size) also, is it best to have hitboxes with dimensions that are multiples of 8 in this case? the main problem is figuring out how to do the "pushing out"... can someone guide me on how to do this? oh, and this game isnt being programmed in c or c++, its in z80 - so i just need to understand the concept, dont need any code :D thanx
Advertisement
well, i got an email saying that since nobody answered this questioned i should answer it because i mustve figured it out by now. well i did! heres how it works:
if u want to check an 8x8 sprite against a map with 8x8 tiles u have to do two checks. the first is the X coordinate check. u have to check the tile underneath the top-left corner of the sprite and the one directly to the right of that, because the sprite will be unaligned 7/8 of the time, right? but anyway, if either of those tiles are blocked u simply align the sprite to either one of them (if the one to the left is blocked, align it to the block on the right, and then check the right and align it to the left if blocked) - do the exact same thing with the Y coordinate and check the tile directly underneath the sprite and the one BELOW. after these two checks the coordinates should be aligned to a multiple of 8 depending on if they were in any solid blocks. the result is it appears as if the sprite is unable to enter any solid blocks. hope that was clear enough
forget to mention: to check the map on a larger sprite (16x16) theres no other way to do it than to check 4 8x8 hitboxes...

This topic is closed to new replies.

Advertisement