Sign in to follow this  
JohnHurt

Platform game player movement

Recommended Posts

I'm currently developing a 2d 8-way scrolling platform game in OpenGL, with maps similar to that seen in soldat. My problem is that i don't know how to test if the player is in contact with a surface. I can detect collisions and apply realistic collision response, but I need to know if the main character is in contact or not, so that when you press the jump button, only a momentary impulse is applied, and also so that any running animations are not allowed. Does anyone have any ideas?

Share this post


Link to post
Share on other sites
I have two solutions, hopefully one is useful to you.

One thing you could implement is all of your level objects (walls, random things to jump on) as individual objects, instead of a static image. Then you need to keep a list of the current level objects on the screen and update that with your player's/camera's movement. Theeeeen, you can do collision detection on the current objects in the player's/camera's current view.

The other solution is simular, you could take your 2d map and make a black and white image out of it. Where there is black is where your player can't go and where there is white he/she can. This can be implemented with simple pixel checking fuctions that both openGL and DirectX support.

good luck and I hope this was helpful,
JDev

Share this post


Link to post
Share on other sites
Its, not the actual collision detection thats my problem - my scenery is made up from individual triangles inserted into an axis-aligned bounding box tree. the problem is, that when you hit the jump button and keep it pressed, the main character will keep rising up. i put in a test so that if a collision with the terrain occured, a flag was set telling the character that he is on the ground...

if ( collision )
on_ground = true;

then if ( jump is pressed && on_ground )
on_ground = false;

the problem is that the character is never truely ever fully on the ground, but keeps bouncing, so most of the time on_ground = false, meaning that the character will not jump.

i've thought about having some kind of tolerance zone near the ground to keep the flag from "flickering".

I appologise if this doesn't seem very clear. :)

Share this post


Link to post
Share on other sites
The approach I've seen used before is to set up 'touch points' on your character. You define a point below and in the center for testing against the floor, one on each side for testing against, walls, and so on. You can set up as many points as you need, perhaps even setting their positions for each frame of character animation (so that it stays accurate); it can be great for doing things like catching ledges (set up a point on the hands, test it against box that covers 'grabbable' edge) or swinging from bars, PoP-style.

Then, once you've got a box-box collision for your whole character, you can start doing point-box collision tests to determine which parts of the character are in contact with the environment.

That's quite an old technique, though. There's probably something better around.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this