Platform Engine - A Few Thoughts

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Platform Engine - A Few Thoughts

Post by Xcmd »

So here are a few thoughts I've had about jumping around in a platformer game, using the Physics engine supplied.

As exampled in Ninjaball's code, a good way to prevent someone from jumping is to check to see if they're colliding with anything. If they are, they can jump. If they're not, then they can't jump. Now, as was pointed in this same thread, it's kind of messy. And I agree. The best way to prevent this is to define different types of solids. If they're ground-based solids, then you can jump. If they're not, then you can't. This would allow silly things like jumping blocks, walls, etc, that won't cause you to be able to jump as soon as you're touching them. This is typical platformer behavior. I would like to point out, however, that this would be more or less tile-based. Sort of. I think you could easily define an entire region as being "ground", which would make more painted and pretty maps more possible, ala Earthworm Jim. You just basically use a series of polygons to define the regions that are "ground", etc.

Another thought I had is that this would work very ideally for a Prince of Persia 2D / Out of this World / Flashback type game, where jumping is only a way to cross chasms or to get up onto ledges.

However if you think about it, the ability to jump as soon as you're colliding with something does enable to you to do things, easily, like wall-jumping and, in Ninjaball's particular case, crawling along the ceiling. Which, for a ninja, is pretty standard fare. I think with a little bit of effort, you could easily do a game as complicated as N the way of the Ninja with wall-crawling and the like if you think it over. I'm sure friction is involved in here somehow...

Anyway. Just some food for thought.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Alex
Prole
Posts: 30
Joined: Mon Mar 09, 2009 1:49 pm

Re: Platform Engine - A Few Thoughts

Post by Alex »

I've made a platform engine that is definitely inspired by N, using the basic faculties of Box2D. There are no special shapes, just a check to see what direction your character is touching against when a collision occurs. And you're quite right, knowing when your character is touching something and where enables things like wall jumping and wall slides to be implemented fairly trivially (with a custom friction function, Box2D doesn't make sliding friction feel very game-like). If you're making a tile-based platformer this would be overkill, but in world defined by arbitrary shapes it seems to work quite well.

I'll be releasing the code as soon as I add a little more functionality to it.
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Platform Engine - A Few Thoughts

Post by Xcmd »

Fantastic! It's good to know I'm sniffing up the right tree.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: Platform Engine - A Few Thoughts

Post by osuf oboys »

Lunar Penguin works by checking the distance (i.e. are you close enough in order to account for bouncing) and the angle of the surface. Note that Rude has mentioned that he will or has already added to the next version the box2d event for when two objects stop touching.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

Re: Platform Engine - A Few Thoughts

Post by Matkins »

A simple solution that works for me. Instead of defining every peice of ground in your world, just define a part of the player character which should be treated as the feet. So add a small extra shape to the body at the bottom of the character, and code your collision callback so jumping can only happen if the "Feet" shape is in contact with a world object. Its width can be slightly less than the player body so that it doesn't touch walls. Now you can jump off anything you can stand on.
AirPump
Prole
Posts: 12
Joined: Tue Mar 24, 2009 7:55 pm

Re: Platform Engine - A Few Thoughts

Post by AirPump »

Matkins wrote:A simple solution that works for me. Instead of defining every peice of ground in your world, just define a part of the player character which should be treated as the feet. So add a small extra shape to the body at the bottom of the character, and code your collision callback so jumping can only happen if the "Feet" shape is in contact with a world object. Its width can be slightly less than the player body so that it doesn't touch walls. Now you can jump off anything you can stand on.
That's a clever idea, but here's my approach to platforming:

For ground, find what objects (that can be stood on) are between the player's collision box's left and right sides. These are objects the player could land on. Now, from these, pick which object is the highest up, and set the upper bound of its collision box (or its collision line) as the height which the player will land at, shifted if the player's location isn't at their feet. If the player is on the ground, they remain so until the height of the floor they are on changes or they jump. Also, the player will not fall through the floor, as if the player should walk over a small gap between platforms, the platforms will be the highest or tie for highest, thus the player's height will not change.

Collision with walls is handled separately.
User avatar
Garotas*Gostosas
Prole
Posts: 41
Joined: Fri Apr 03, 2009 12:15 am

Re: Platform Engine - A Few Thoughts

Post by Garotas*Gostosas »

When you only can jump when touching something, like the floor etc, how would you do "double-jumps"? Many Characters nowadays can do that, like in Mario 3D for Example.
But you can't jump when your in air, because theres no surface to touch. Lets say I would want double jumps in my game, then I would have to start a small timer or a clock or something everytime I jump succsessfully. Because you have to do the double jump always with the right timing, right? so i press jump, the game checks if i'm touching something. lets say i do. the game lets me jump and starts a timer, for like 2 seconds. if i press jump again, just before the timer runs out, i do a double jump. something like that maybe... How do you would do it? Is there even such a timer? (I mean, i'm just doin the tutorials)
I LOVE GAME, YEAH!
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Platform Engine - A Few Thoughts

Post by Xcmd »

When I was playing around awhile back, I ran two varibles: hasJumped & hasJumpedAgain -- Basically, when I jumped, I set hasJumped to True. So when I hit my "jump" button again, it checked if hasJumped was True. If it WAS true, it set hasJumpedAgain to True and did the jump code again. When the player landed, the game reset both variables back to False. That's just one method and not a very clean one, especially if you want them specifically to jump only at the height of the jump. Mine it didn't matter, I was just playing around.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
Garotas*Gostosas
Prole
Posts: 41
Joined: Fri Apr 03, 2009 12:15 am

Re: Platform Engine - A Few Thoughts

Post by Garotas*Gostosas »

Xcmd wrote:When I was playing around awhile back, I ran two varibles: hasJumped & hasJumpedAgain -- Basically, when I jumped, I set hasJumped to True. So when I hit my "jump" button again, it checked if hasJumped was True. If it WAS true, it set hasJumpedAgain to True and did the jump code again. When the player landed, the game reset both variables back to False. That's just one method and not a very clean one, especially if you want them specifically to jump only at the height of the jump. Mine it didn't matter, I was just playing around.
Yeah, sounds good. Clever idea. Now that you say it I wonder why I didn't think of it myself... :monocle:
I LOVE GAME, YEAH!
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Platform Engine - A Few Thoughts

Post by Xcmd »

it's pretty basic, you would've thought of it sooner or later. :)
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Post Reply

Who is online

Users browsing this forum: No registered users and 226 guests