Skipping down ramps in a platformer

Hey all, just started using Unity3D a couple of weeks ago, loving it. One thing I’m curious about is if there’s some standard way to keep a player from “hopping” down a slope in a 3D platformer a la Super Mario 64. If I drop a First Person Controller prefab onto my level geometry, he runs around flat surfaces fine, runs up ramps no problem, but he doesn’t really follow the geometry running down a ramp. I noticed the player in the default island level did the same thing, it’s like all the slopes have a HopScotch component. :lol:

I can “fix” it by massively increasing my gravity, which of course messes up my jumping. I’ve already gone and done things in my engine to make things work only to find out as I keep reading that Unity3D has a built-in way to do what I went and did in script, so I’m just wondering what the standard approach is to correcting this behavior. I can’t imagine I’m the first person to notice this but most of my searches give some bug about going up slopes … thanks for the help.

EDIT: The way I found to try to fix this is to simply calculate the movement as normal, but before actually calling Move() I set movement.y to -1. Of course, I have to make sure he’s not jumping, and that he didn’t just walk off a ledge instead of down a ramp, etc. I’m not really sure how to check if they walked off an edge or just down a slope; CollisionFlags.CollidedBelow would be 0 either way right? Hoping there’s a better way … anyone?

Obligatory bump. I know I can’t be the only one that’s dealt with this, notwithstanding aforementioned search results …

Daily bump-smack. Jumping while walking down a ramp is hit-and-miss; am I on the ground? Am I not? I know it’s possible to follow the slope because if I make a box with Ice physics and drop it on the ramp, it slides perfectly … need my character to do that now.

You could get the surface normal be doing a simple straight-down raycast, or use the info available from the collision event. You can use this normal to rotate your movement vector into the surface plane before you perform the Move().

Hmm. Depending on how Unity handles that info I could see it working. Gave me a few ideas to try. I won’t have a chance to try it for a bit but thanks for an answer.

Surprised I didn’t get more of a canned answer. I can make Goober from the demo essentially stand in empty space if I position him right off an edge because of the shape and standard behavior of the CharacterController capsule and it looks horrible. Surely others have come up with workarounds …

Even the CC will give problems with running down ramps.

When you call move, the CC does a linear cast of the capsule shape using your whatever vector you feed it, when the magnitude of the cast is less than the distance from the CC to the ramp its obviously not going to get a “hit”

Doing a linear cast down would probably work.

The easiest way (though the most cumbersome) would be to simply mark off areas that are “cliffs” with a trigger.

I had the same problem, but after a little research, I have found a pretty neat fix, it isn’t totally perfect, but it does the job right and is easily configurable…

So, if you are using the 3D Platformer “Third Person Controller” script, then there is this neat function:

function CalculateJumpVerticalSpeed(targetJumpHeight : float){
	return Mathf.Sqrt(2 * targetJumpHeight * gravity);
}

And here comes the actual movement calculation variable

var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0);

As you can see, it gives Vector3 values of X=0, Y=verticalSpeed, Z=0… So my research was checking how often and on what causes verticalSpeed is updated and it turned out that it’s called every Update(); by ApplyJumping(); function and it changes every time you make a movement down a slope.

After little experimenting, my fix for this is adding a new variable to the controller script “var collisionFix”, with your own defined value (although, default 2 does the trick).
Next, change the function and variable to following.
Function:

function CalculateJumpVerticalSpeed(targetJumpHeight : float){
	return Mathf.Sqrt(2 * (collisionFix * targetJumpHeight) * gravity);
}

movement variable:var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed-(jumpHeight * collisionFixer), 0);

Oh, looks like I forgot to explain what is it meant for :smile: EDIT:
Basicly, you set the verticalSpeed value while not jumping in a minus value of 2 times your jumpHeight which results your “foot” collision to be sticked into the terrain/ground/whatever not glide above it a little value… and when jumping, you set it two times higher, so you get back your “jumpHeight”. Something like that. Ok, off to school!

So yeah, the result is awesome, no “hopping” down on little slopes, no “uber” fast jumps because of llame gravity. Only thing which should be improved is going down on steep slopes, but that could be fixed with exact value of collisionFix, i hope. And yes, the thing is you are moving normally down on those slopes also.

But as a temporary fix it’s good, hope it helps out anyone else :slight_smile:

P.S. Sorry for bad formatting and description, it’s 6:50am here, really sleepy, tried to do this all night. Got any questions, freely ask here!

Please give some feedback, so I could try some improvements or stuff.