Map collision ideas

BlitzMax Forums/BlitzMax Programming/Map collision ideas

Twinprogrammer(Posted 2013) [#1]
Hey guys,

I've been working on a game with map collision and detection. I use a piece of code that is somewhat related this:



I was wondering if anyone has any other ways of detecting map collisions.


ImaginaryHuman(Posted 2013) [#2]
That's basically it. An alternative collision approach is to let the player potentially overlap the wall block, detect that he is doing so, then `move him backwards` in the opposite direction that he came from, or push him to the very edge alignment with the wall.

I haven't really programmed something like this myself but I'd probably do it the way you are - just checking the surrounding cells and not letting the player move if the upcoming cell is solid.


Who was John Galt?(Posted 2013) [#3]
Yup, pretty much what you're doing, twinprogrammer. Why thwe question though, unless you want something that your collision is lacking?


AdamStrange(Posted 2013) [#4]
hmm, ok lets open the birdcage to the cat...

- lets assume that the map is map[x,y], and x,y are integers. and this can be mapped as a zelda style or rogue style.

your main character (lets call it man) can live at any map location, so we have Man.x and Man.y

- we can check the contents of a map by checking Man.xy against Map.xy and get the result as given in the first post

----- so far so good :)

but this assumes that we can only move in integer blocks! For smooth movement that should ideally be in float

so you don't move right by going Man.x+1, you actually do it by Man.y+0.1
That means at any time you Man can occupy up to 4 Map positions at once, and your map checking has increased by a factor of 3.

- 3 I hear you say, where do you get this from?
- Man.x = 3, Man.x+0.1 = 3.01, so we check Map.x,y-1 Map.x,y Map.x,y+1

- we need to check the + and - y as we can't be sure that y will be a whole number now.

I could go on about the width of walls vs Man position, or small Man vs Big Monster...

Just a thought??


Henri(Posted 2013) [#5]
Hello,

back in the day when was doing a Super Mario clone and moving the character was done in fractional numbers I checked something like:

a) Current location
b) Character movement amount
c) If a + b is inside solid then count the max movement that doesn't put character inside solid
d) Draw character


-Henri


Twinprogrammer(Posted 2013) [#6]
Thanks for all of your input guys!