Jump Game Logic

In my game the character can jump onto different surfaces. Right now, the player is allowed to jump once, and then may not jump again until he comes in contact with a “jumpable surface”.

This logic doesn’t really work as a player can jump up the side of a wall.

How do you guys tackle jump logic? [import]uid: 49205 topic_id: 9356 reply_id: 309356[/import]

Whatever you are doing to state that the ground is a “jumpable surface”, could you simply not make the wall a “jumpable surface”?

I haven’t created many apps where jumping is involved but when I have I’ve simply said that the ground and any platforms were able to be jumped off which the walls were static physics objects with no jump-related rules attached. [import]uid: 52491 topic_id: 9356 reply_id: 34215[/import]

I do have an isJumpable attribute. I sort of simplified my explanation a bit.

I have a rotating platform so the player should be allowed to jump on it when it’s flat, but not when it’s vertical. [import]uid: 49205 topic_id: 9356 reply_id: 34290[/import]

Can you specify that if your platform is at a rotation that it would be upright that it’s no longer “jumpable”?

Or if rotates constantly you could use a timer to change it from “jumpable” to not every x seconds, where appropriate, and vice versa.

(I’d think the first would be simpler.)

Peach :slight_smile: [import]uid: 52491 topic_id: 9356 reply_id: 34365[/import]

I have actually the same problem with my game. It’s been a long time since I tried anything as my internship is holding me back but I got an idea this morning:

Write a function like this somewhere in your code:
[lua]local function canJump()
local vx
local vy

– get the velocity
vx, vy = player:getLinearVelocity()

return ( vy == 0 )
end[/lua]

and in the runtime event listener handling the player sprite
[lua]if canJump() then
player.canJump = true
end[/lua]

I don’t know if this works at all, this is just an idea. [import]uid: 51516 topic_id: 9356 reply_id: 34371[/import]

@peach

Thanks for the suggestion! I was hoping for a cleaner solution (that would apply to different types of objects as well) but that seems like a pretty good substitute if I can’t find anything else.

@seth

So if I understand correctly, that code will theoretically let the player jump if his yVelocity is 0? Some sort of variation of that could work…thanks for the idea!

I’ll update you guys on what’s going on when I can. I’m visiting Stanford for a few days so won’t be able to program.

[import]uid: 49205 topic_id: 9356 reply_id: 34405[/import]