Player pushed down when jumping by step-offset-amount

Hello all,

When I am jumping with my player, pressing W and the player is colliding with a wall or an object (internal unity collision detection, not my own script) and he reached his highest point, in the next frame the vertical velocity starts being negative. Now the player should slowly interpolate down, but I see a drop in the character controller position by a lot more. My analysis shows, that it is pushed down by the step offset amount, which is set to 0.71. When I change the step offset to for example 0.6, the position drop is also 0.6. So its always the step offset amount. And I have no clue, why this is happening. Any ideas?

Here’s the jump code:

public override void OnEnable()
{
     data.verticalVelocity = Mathf.Sqrt(data.jumpHeight * data.gravity);
     data.isJumping = true;
}

 public override void Update()
 {
    data.horizontalDirection = data.transform.right * data.x + data.transform.forward * data.z;
    Vector3 movementSpeed = data.horizontalDirection.normalized * data.speed;
    data.verticalVelocity -= data.gravity * Time.deltaTime;
    movementSpeed.y = data.verticalVelocity;
        
    data.controller.Move(movementSpeed * Time.deltaTime);
 }

I have debugged the controller position, and I see this drop there as well:
image

Thank you Huxi

1 Answer

1

I have found another bug report of this issue: https://forum.unity.com/threads/character-controller-unexpected-step-offset-behaviour.640828/. Seems to be a unity bug for along time. As a workaround it is suggested in the article do disable the StepOffset while jumping and then reenabling it again. I did so and it works.