9
\$\begingroup\$

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.

\$\endgroup\$
7
  • \$\begingroup\$ It seems like the transition of flat ground to steep hill would slow the player down enough to make the jump. If they want to maintain their speed, they would jump before the slope. Just FYI, I think your question is kind of a "help me decide" type question, making it kind of opinion based. \$\endgroup\$
    – House
    Oct 23, 2013 at 17:24
  • \$\begingroup\$ @Byte56 Perhaps some opinion may enter the mix, but I think this is still a good question. Some of the best questions on this site have an air of opinion about them. A good answer might point out shipped solutions. \$\endgroup\$ Oct 23, 2013 at 17:56
  • \$\begingroup\$ @ktodisco I agree, the answers can turn a borderline question into a great one. (Though the last of your examples is closed, rightly so). \$\endgroup\$
    – House
    Oct 23, 2013 at 18:04
  • \$\begingroup\$ One possibility, which I think I've seen (I know that's not particularly convincing) might be to make a jump's direction relative to the angle of the ground underneath you- so jumping on a downward slope would gain you some forward momentum, but not jump as high, while jumping on an upward slope would send you higher with reduced forward momentum (think of the jump as pushing off the ground) \$\endgroup\$
    – Tin Wizard
    Oct 23, 2013 at 19:29
  • \$\begingroup\$ @Amadeus9 that's a good point, but I think in this specific case I wouldn't apply. Reducing the speed when jumping will still end up creating a slope collision eventually, since the speed increases without limit. \$\endgroup\$
    – you786
    Oct 23, 2013 at 23:26

3 Answers 3

12
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the detailed answer. For the record, I ended up removing all up slopes that are too steep. \$\endgroup\$
    – you786
    Nov 3, 2013 at 17:29
1
\$\begingroup\$

For anyone else who comes across this, I got around it by having a minimum number of frames that must pass in the jump animation before collision with the hill is registered. That way you have a grace period to allow the character to get up a little bit without worrying about the slope collision.

\$\endgroup\$
-1
\$\begingroup\$

the raycast is a good idea,you may use ray judge whether it is a slope ,then you can controll the velocity by changing the player velocity.

\$\endgroup\$
1
  • \$\begingroup\$ You could significantly improve this answer by explaining how. \$\endgroup\$
    – user1430
    Sep 1, 2015 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .