How do you know you are on the ground?

Started by
2 comments, last by Elehisie 19 years, 5 months ago
Here is a deceptively difficult problem i'm dealing with. The game is a 2D platform jumper ala Super Metroid. I would like to get some input from others who have dealt with this before. Basically, how do you know when you are on the ground? I can get my character to jump and run and all of that with the current physics and movement system i have. But i have problems getting my character to run up and down slopes. I know how to do it, but i want to know how to do it well. My world is object-based (as opposed to tile-based, although it could be that too if i wanted), where each object has a convex polygon for it's collision geometry. A floor might be a simple box and a slope could be a triangle. As far as staying on the ground is concerned, basically i'm keeping a player state like JUMP, RUN, IDLE etc. I determine the state with checks like "if i was falling but now my change-in-Y is around zero, i'm now IDLE". Is that a good way to do it? Some things i would like to have: - I want to eventually be able to hang from the ceiling (like swinging on monkey-bars) and also stick to the walls like spiderman. So the slope/floor walking code needs to be able to adjust to whatever world object i want to stick/hang/walk across. - I want to be able to use free-floating object in addition to tiles. The problem with that is that if i step off an object, i need to know if there is another object next to it to continue walking across. Otherwise i fall and my player state reverts to "jump". In other words, i need to nicely transition from walking on object A to object B. I also need to know if there is an object B. - I would like the code for this to be reasonably reusable for enemies and such too. I want those little whooly Metroid critters that walk all around platforms and up and down walls and ceilings :-) If you have any stray thoughts on the matter, please please comment. Thanks for your help. PS: i'm already aware of the jnrdev articles, but any other resources would be appreciated.
Advertisement
Well, maybe you're way past this already, but what I do is this: I apply the gravity to the object, such as the player, and then collision test it:

if collision with bottom  (  move player up far enoguh to not hit)else(  if not jumping     set state to falling)


Also I inserted a collision check with the top in the first part of the if in my game, to not get in an endless loop when the player hits the ceiling and the floor at the same time.
I think you could assign flags to objects that have other objects right next to them.

Say, one flag that determines whether there is a box to its right, another flag for its left. So what you do is, when you step off an object, you continue to walk/run if a flag is set.

Platforms     ____  ____  ____        ____    |0  1||1  1||1  0|      |0  0|____|____||____||____| ____ |____|_____Ground ^			 


(Damn ascii got messed up before..)
I disagree from you when you say "object based as opposed to tiles"

the way I code, all tiles ARE objects, with properties holding "what image it should show", "solid" flag, "foreground" flag, "background" flag, ...

so... to draw a map you have a collection (list, matrix, whatever) of objects (tiles) from which you can check properties.

I also apply gravity to them, so the sprites always have some "speed" or movement change on the Y axis, unless they find a solid object (tile)...

like...

while (tileUnder.solid != true) {
++sprite.Y }

:)

=====================
Quote:
PS: i'm already aware of the jnrdev articles, but any other resources would be appreciated.

ever heard of a book called: AAA - Action Arcade Adventure Set ??
if not, googgle a bit for it, you cna find the whole book to dl/print on the web, posted by its own author lady. I long lost the link cuz I printed it ^^;;;; there was a cd along with the book, and you can also dl the contents from the cd there on her website :)

also, you can try to find "Denthor Asphyxia's Game tutorial" its very asm-dos oriented, but he gives lots of usefull information <--- for this one, I started getting "404" about 3 yearsa ago. Maybe it moved or was definatelly put down. it happened before you know, that one moved URL about 2 times, then i lost track of it

This topic is closed to new replies.

Advertisement