Sunday, December 1, 2019

physics - How to handle jumping up a slope in a runner game?


In an 2D endless runner, what should happen when the player is running "too fast" up a slope and jumps?


For example, in a "normal" case:


    .O.

. __..O_____
. /
. /
O/
_/

If he is moving to the right slowly enough, he will jump upwards and land on the flat part of the surface. However, if he is moving too fast, the jump will have no effect as his forward motion will bring him back in contact with the slope before he can get high enough to pass over it. When the speed is sufficiently high, there will effectively be no jump.


     _________
/
.O/

O/
_/

Are there any known ways to solve this issue? I know it's physically correct*, but are there techniques that other games use to overcome this in a reasonable manner?


As a last resort I'll have to just remove all slopes that are too slanted.


*If you constrain the player to never jumping backwards.



Answer



Here are some examples of how games (runner or otherwise) have handled this situation. There is no "best" and you still have to decide which one is right for your game.


The physically "correct" way (vertical impulse)


To jump, you add a vertical impulse (red) to your movement velocity (green). The resulting velocity (blue) will always take you above the slope, so as long as your slope doesn't get too much steeper soon, your character will always jump above the slope.



tiny wings


The caveat is that if your character is racing up a steep slope, you can now jump up very high.


Perpendicular jumps (Sonic)


When jumping, your jump impulse is in a direction (red) perpendicular to the slope (green). You may remember this behaviour from the Sonic games.


Sonic


The caveat is that on very steep slopes, you often end up jumping backwards.


No jumping on slopes


Maybe you decide that slopes are kind of special and it doesn't make sense to jump on them. For example, stairs are a special kind of slope, which in some games you can't jump on at all.


castlevania 3


The caveat is that, whenever you take away control from the player like this, you need to clearly communicate the expectations, otherwise the player can get frustrated. For example, Castlevania uses a special "stair climbing" animation to make it clear that it's a special kind of motion.



No running on steep slopes


Another option is to make it impossible to climb slopes that are too steep - players slide down as if it's a wall-like obstruction. Since they are falling or sliding down, it's clear that they can't jump during this time either.


No steep (up)slopes


You could take the easy way out and entirely remove slopes that will give you such problems. This is not as bad an idea as it sounds, because walking up slopes is no fun; walking down slopes is way more exciting!


ski safari


No slopes (the Mu answer)


When it comes to gameplay, I'm a fan of minimalist design - as the saying goes, "perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away". Do slopes serve a useful gameplay purpose, or do they just look good - i.e. are they fun? After all, it's perfectly fine to have a runner with no slopes at all.


canabalt


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...