Hi everyone, I’m having some trouble playing the right animation when my character is moving down a hill. With the way I have my controller set up, it looks like the character actually comes off the ground when moving down any hill, then immediately falls back onto it, which causes my grounded flags to flip back and forth like crazy. I built my controller off of one of the sample project ones, and it seems like the only thing that fixes the problem is if I crank the gravity way up. Is there a better way to do this though? Here’s what I have so far, any help is much appreciated! Thanks! ![]()
function Update() {
//get direction and speed in X-Z plane
UpdateSmoothedMovementDirection();
if(!grounded)
{
falling = true;
}
else
{
verticalSpeed = 0.0;
// We are in jump/fall mode but just became grounded
if (jumping || falling)
{
jumping = false;
SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
falling = false;
}
// Jump
if (canJump Input.GetButton ("Jump"))
{
verticalSpeed = jumpSpeed;
jumping = true;
SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
}
}
// Apply gravity
verticalSpeed -= gravity * Time.deltaTime;
var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0);
movement *= Time.deltaTime;
// Move the controller
controller = GetComponent(CharacterController);
flags = controller.Move(movement);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
isOnGround = (flags CollisionFlags.Below) != 0;
hasHitHead = (flags CollisionFlags.Above) != 0;
// Set rotation to the move direction
transform.rotation = Quaternion.LookRotation(moveDirection);