x


Character stuttering down slopes

Because of a relatively low gravity on my character controller, the character walking/running animation stutters when moving down slopes. (Every few milliseconds it recognizes him as being in mid-air, so it keeps switching between animations). I can increase the grounded gravity to fix this but then when the player walks off a ledge they fall like a dead weight compared to when they fall from a jump. Any ideas how I could try overcoming this issue?

function ApplyGravity () {
    if (controller.isGrounded) {
       // Keep reset when on ground
       movement.verticalSpeed = -movement.gravity;
       movement.airTime = 0.0;
       movement.leaping = false;
       activeInput.move = true;
    }
    else {
       // Start counting time in air
       movement.airTime += Time.deltaTime;

       // When we reach the apex of the jump, set reachedApex to true
       jump.reachedApex = jump.jumping && !jump.reachedApex && movement.verticalSpeed <= 0.0;

       // When jumping up we don't apply gravity for some time when the user is holding the jump button for a higher jump
       var extraPowerJump = jump.jumping && movement.verticalSpeed > 0.0 && jump.jumpButton && transform.position.y
         < jump.lastStartHeight + jump.extraHeight && !IsTouchingCeiling ();

       // Apply gravity to vertical speed
       if (!extraPowerJump)
         movement.verticalSpeed -= movement.gravity * Time.deltaTime;

       // Make sure we don't fall any faster than the terminal velocity
       movement.fallSpeed = -movement.terminalVelocity;

       // Check for wallsliding (and if so, decrease fallSpeed)
       WallSliding ();

       // Check vertical speed against terminal velocity
       movement.verticalSpeed = Mathf.Max(movement.verticalSpeed, movement.fallSpeed);
    }
}
more ▼

asked Mar 03 '12 at 07:55 PM

Essential gravatar image

Essential
461 48 65 79

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I see two ways :

  • Add a delay between the calculation of is grounded and it's affectation like once isGrounded is supposed to be turned off, start a coroutine which turned isGrounded to off after 0.5 only if it wasn't grounded back inbetween.
  • Cast a ray downward, if it's far enough you can consider yourself not grounded. You might force it for a jump though.
more ▼

answered Mar 03 '12 at 08:51 PM

Berenger gravatar image

Berenger
11k 12 19 53

Thanks for the reply Berenger.

In regard to your first idea, I considered that but was afraid it might look odd when falling off a normal edge (fast falling suddenly changes to slow) but maybe if it's short enough it will work okay. Will give it a try.

Mar 04 '12 at 02:53 PM Essential
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x50
x21

asked: Mar 03 '12 at 07:55 PM

Seen: 900 times

Last Updated: Mar 04 '12 at 02:53 PM