Collision reaction in tilegame

BlitzMax Forums/BlitzMax Beginners Area/Collision reaction in tilegame

Kief(Posted 2010) [#1]
Hi. My first post.

I working on a 2d top-down-view game where the player drives around in a car. Don't worry I'm not trying to copy GTA I, even though the view is basically the same. In the end it should be more of a sci-fi adventure.

My current progress can be seen in this youtube clip: http://www.youtube.com/watch?v=ajPMOHCLLPU

I did a few trial and error coding just to get aquinted with blitzmax.

I'm satisfied with the simple mathbased collision Detection, so my problem is (just) to make the collision Reaction so it looks natural.

I have tried to program every possible scenario in a series of if-statements, but even with just 4 collision points the code is becoming extremely long. Keep in mind that the car bounces off the walls in different directions depending on whether it hits the tile from above, below, left or right. Additionally I want the car to slide and align parallel along the wall at some angles, while it should crash frontally (align perpendicular), when it hits the wall almost frontal.

There must be an easier way, other than coding an if statement for each situation?

Any input is appreciated. Thanks in advance.


Jesse(Posted 2010) [#2]
why don't you try one of the physics engines, like chipmunk physics from Brucey's modules? I am sure you will get better result with a lot less stress.


jkrankie(Posted 2010) [#3]
I'm pretty sure Physlite comes with a top down driving example...

Cheers
Charlie


Kief(Posted 2010) [#4]
Well, it's not exactly the answers I was expecting. I was kind of hoping that I could avoid importing any modules. (It's just that I'd like to code everything myself, so I know what's going on.)

Thanks for the advice anyway. I will definitly look into those, if I don't find any other solution. First I will try to rearrange the nesting of the if statements.


_Skully(Posted 2010) [#5]
You could do a very basic verlet type link between each corner of the car and then let the verlets control the result.

Basically, you have 4 points that try to stay the same distance from each other in a X inside a Box (XBOX lol) pattern. When one point collides it will adjust its resulting position to outside the collision point moving back along its movment normal... after that the verlet links will cause the other points to move as well.. then you just have to figure out the orientation of the car relative to those points and it should appear more realistic.

Not much time now.. I might explain further later.


Kief(Posted 2010) [#6]
Thanks. I got it working somewhat better now.

I was trying to do everything at once in my first approach, but now I have seperated the reaction into more parts, so it is easier to handle.