- Home /
Prevent character from autojumping when moving down a slope.
I have a character that moves automatically using a characterController. I also have it set up so that the character jumps when reaching the edge of a platform. This works fine for flat, level platforms or when moving uphill, but I run into an issue when there is a downward slope to platform. It is so sensitive to the distance to the ground that the character jumps automatically when moving downhill. I have tried to reduce the sensitivity by adding in a timer to count how long the character has been off of the ground. Like so:
private var jumpTimer : float;
var jumpSensitivity : float = 0.1;
//Jumps when reaching the edge of a platform
if(!controller.isGrounded && !isJumping && !isClimbing && !preparingToLaunch)
{
//Reduces sensitivity to gaps under the character so it only jumps
//at ledges and not if the terrain declines slightly
jumpTimer -= Time.deltaTime;
if(jumpTimer <= 0 && !controller.isGrounded)
{
jumpTimer = jumpSensitivity;
moveDirection.y = jumpForce;
isJumping = true;
animation.Play("Jump");
}
}
Unfortunately, this only seems to work if the timer is set to around half a second or so, which makes it looks really odd when it jumps off of an actual ledge because it begins to fall, then jumps. I've even tried increasing the gravity when the character is on the ground, but it only works if the gravity is increased to an extreme amount and that causes problems when the character steps off of a ledge as well.
I'm wondering if there is an easier way to go about this. Any suggestions are appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164734im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
character controller wont rise when I Jump :( 1 Answer
Character falls over and bugs out when animator is enabled 0 Answers
Need to forbid jumping from another script 0 Answers
Player sticks to ground occasionally after trying to jump 0 Answers
AI movement using Character Controller, turning problem 1 Answer