- Home /
Character Controller slowing down after climbing a slope
I have a scene where my Character Controller must move between boxes of varying heights, seperated by small staircases. In order to do this, I have used a tilted box collider for the staircase collider, which the character is able to walk up like a ramp. As I have set the Character Controller slope speed multiplier to a consistent value of 1.0, the character is able to walk up staircases of varying gradients at a consistent velocity.
However, when the character reaches the top of a staircase and begins to walk again on a horizontal plane, their movement speed drops dramatically, seemingly inversely proportionally to the steepness of the staircase collider. Their speed snaps back to normal after moving a seemingly random distance. I am using Unity 4.1.2, and after altering a number of Character Controller variables and experimenting with different kinds of colliders I still can't seem to resolve this issue.
@Edy - likely have to see the code. You should do a Debug.Log() of the movement vector just before you pass it to the CharacterController to see what is going on. You should also take a look at the collision flags to see if there is a collision issue.
Answer by Edy · Sep 28, 2014 at 11:01 AM
Most likely the character is encountering a steep normal at the top of the slope. When this happens, the velocity dramatically decreases. The fix is modifying the CharacterMotor.js script, specifically the function AdjustGroundVelocityToNormal here (line 364 in my version):
desiredVelocity = AdjustGroundVelocityToNormal(desiredVelocity, groundNormal);
In my case I've voided that function completely, so the velocity is preserved no matter the slope of the ground:
desiredVelocity = desiredVelocity; // AdjustGroundVelocityToNormal(desiredVelocity, groundNormal);
You might prefer to tweak the AdjustGroundVelocityToNormal function not to have so much influence in your character's velocity.
EDIT: You can safely void the CharacterMotor.AdjustGroundVelocityToNormal function and tweak the velocity with the slope using the curve CharacterMotor.slopeSpeedMultiplier. It's a much more convenient way to fine tune the velocity of the character with the slope of the ground.
Holy sun, Thank you so much for this!!
PS: I would upvote but I dont have enough reputation to do so :(