How do you handle Ramps and Jumps in a Physics Based 2D Platformer?

I’m working on a Character Controller for a physics based 2D platformer using the Unity Assets Pack character controller as an inspiration, and I’m having some trouble dealing with ramps. Well that’s where I started anyways, actually I’m having a problem with my solution for ramps, since it makes it hard to control jumping.

Let me explain.

When I started, I made a player character who had a rigidbody2d and a capsulecollider2d, and I used a script that added a force in the x direction in relation to the raw input. The script also allowed jumping, using an impulse on the y axis when space was depressed, but only when the player was grounded. The grounding check is done by using a circlecast down to a point at the player’s feet.

This was functional, but it had some problems. The jumps were floaty, because they allowed the player to move at his full speed in midair, but more importantly it had issues with ramps. When I put an inclined boxcollider2d in the scene and went up it, the player would slide up it at full speed, and when he reached the top of the ramp he would ‘hop’ off the top. Worse was going down a ramp, though, because the player would ‘hop’ off the edge and float down without touching the ramp.

At first I thought to increase the mass of the character so gravity would keep him down, but this didn’t seem to affect the hops at all, it just increased the amount of force needed to jump.

I solved the ramp issue by putting a downward force on the player while he’s grounded and moving. This made it so that the player would move slower up ramps (more realistic!) and nolonger hop off the tops of ramps in either direction.

However, it also made it so that I can’t jump while going up ramps unless I stand still (because the character is grounded on the second frame of the jump and thus the force pushes him down) and the jumps were still floaty.

I’ve been struggling with methods to make the jumps less floaty. The best solution I’ve found so far is to put a lighter downward force on the player during jumps, but why doesn’t increasing the mass do this on its own? I also tried dropping the player’s x speed while they were in midair but this resulted in the terribly unrealistic slowing down when you jumped.

So, I want to know how YOU handle this sort of thing. I’m a bit stuck.

Wow, this sounds somewhat like an issue I’ve messed around with solving for some time.
I don’t work on it a lot, but was trying it last night (in 3d but similar issues). I added an extra gravity multiplier when I was jumping to my character. I use zero drag on my character also. Now my jumps aren’t perfect, still (maybe some different issues), but I’d say if not perfect for floaty, they’re better than they were.
I don’t think mass ever affects the falling speed. Drag does that. Mass can affect how an object is moved with force, too, of course… Anyways, not sure if this will help you…

It’s a little helpful! At least, it’s nice to know others have had these problems. It’s also good to hear more information about how the mass and gravity and drag work.

Ya, really caught me off guard the “floaty” - ness when I began… I guess it still does, sort of. I worked on my little hobby project, again today, for a little while. I think adding extra gravity multipliers to the Rigidbody is nice. At least in my situation, the jumps seem to act much more nicely. I also added the same thing for when my character is falling. :slight_smile: Previously, my character could half float/fall lol. Now it’s much better.

Hopefully you find a solution that works well for you. Best of luck :slight_smile: