Character Controller stuttering with gravity problem

Hey guys, I’m getting some horrible stuttering when my player moves down a slope, everything else seems fine - this is how I’m currently doing the movement and gravity stuff:

if(!controller.isGrounded)
{
     moveDirection.y -= gravity * Time.deltaTime;
}

controller.Move(moveDirection * moveSpeed * Time.deltaTime)

All this is in a function called MovingUpdate() which I call when the thumbsticks are pressed down (I monitor thumbstick activity in an update)

Any ideas how I can fix this? I’m having the camera follow the vertical movement of the player so you really see the jitter quite badly :confused:

I don’t know if this has anything to do with it cause I’m seeing it in my game also without gravity but just when I’m moving slow. Your multiplying gravity by the Time.deltaTime multiple times. Also make sure your calling this function from within FixedUpdate and not Update.

Have a look at this.

–Eric

Hah, awesome thanks Eric, that looks like the same problem so I shall pull apart the code and figure out what its doing :slight_smile:

Yea same. I even disabled gravity in my scenario and yet still saw the jitter so I’m not sure it’s related to this article though.

Well, that fixed it :slight_smile:

All I did was made it so my forward movement always has -0.75 in the y value so it’s always pushing down a little bit - totally fixed the problem

I know I’ve said this before, but this is why I love the community here - you guys are awesome :slight_smile:

So I changed it from this:

if(!controller.isGrounded)
{
     moveDirection.y -= gravity * Time.deltaTime;
}

controller.Move(moveDirection * moveSpeed * Time.deltaTime)

to this:

if(!controller.isGrounded)
{
     moveDirection.y -= gravity * Time.deltaTime;
} else {
     // always push down a little
     moveDirection.y -= 0.75;
}

controller.Move(moveDirection * moveSpeed * Time.deltaTime)