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.