Physics: Stop double-jump, but ensure single jump

Get help using Construct 2

Post » Fri Mar 16, 2012 8:04 pm

Hey all,

I'm new to Construct 2, and I'm taking a stab at my first real game (after playing with some of the examples, making a few prototypes, etc.). First of all, this is an awesome engine and an awesome community, so thanks to the Scirra crew for making this!

So, my problem: I have a rolling-platformer type game where I am solely using the "Physics" behavior, not "Platform". The player is a rolling ball, and they can collide with objects (like moveable crates) and platforms (not moveable).

I want to enable jumping in this game (it's the only real action controlled by the player). Currently, I give the player a neg. Y impulse on key press. However, with this method, if you mash the key, you can do infini-jump, and I want to restrict the player to single jump. That said, I want the player to be able to jump again after they have collided with an object below them (this is key, I don't want you to be able to infini-jump up walls).

My current implementation is to give the player an instance variable for jump count, defaulted to 0. The player can only jump when jump count == 0. When they jump, I set jump count to 2, and subtract 1 from this value any time the player's velocityY is close to 0 (-1,+1). Ideally, 1 is subtracted at the peak of the jump, and again on ground contact, and this works well in basic terrain situations.

This does not work well, however, if the player lands on a crate that's on an incline, a sloped platform, etc. It seems like jumping should be possible in these situations, but it's not since the Y velocity hasn't leveled off to 0.

Is there a better way to restrict to single-jump? I know Platform behavior gives recognition when a sprite touches platforms, is there anything like this for Physics behavior?

Thanks!
B
3
Posts: 10
Reputation: 520

Post » Fri Mar 16, 2012 8:15 pm

Well, of course I just figured this out.

To anyone interested:

I used the same jump count instance variable, but I set it to 1 on jump. Instead of decreasing by 1 when the player's velocityY is 0, I now:

Check for collision with the level objects. I ensure that the objects are below the player before setting jump count to 0. I also ensure that the difference between the X values of the player and the object are close (this prevents wall scaling).

Cheers!
B
3
Posts: 10
Reputation: 520

Post » Sat Mar 17, 2012 11:54 am

Dude, can u upload a capx. file? I only learn with examples... Thanks!
B
20
S
2
G
1
Posts: 32
Reputation: 1,997


Return to How do I....?

Who is online

Users browsing this forum: alextro, MarkStockley, Yahoo [Bot] and 0 guests