Inconsistent jump height when rotating PC left or right

I am developing an endless runner mobile game. Similar to Subway Surfers, I make my player character (PC) rotate slightly left or right and then return to facing forward when sliding left or right. The issue is that this rotation makes the character’s jump inconsistent, resulting in different jump heights.

How can I make the jump consistent? Below are the scripts I am using.

In PlayerController script:

public void SetVelocity(Vector3 velocity)
{
    CController.Move(velocity * Time.deltaTime);

    //Rotate the player a bit where is going
    Vector3 dir = CController.velocity;
    if (dir != Vector3.zero)
    {
        dir.y = 0;
        transform.forward = Vector3.Lerp(transform.forward, dir, data.RotationSpeed * Time.deltaTime);
    }
}

In PlayerJumping script:

public override void Enter()
{
    player.velocityY = data.jumpForce;
}

private void UpdateJumpMovement()
{
    // Aplly gravity
    player.velocityY += data.gravity * Time.deltaTime;

    Vector3 pos = Vector3.zero;

    pos.x = player.SnapToLane();
    pos.y = player.velocityY;
    pos.z = player.currentSpeed;

    player.SetVelocity(pos);
}

Didn’t read your code, but it sounds like a frame rate issue.

Are you multiplying with delta time?

1 Like

Yes, I multiply with time.delta (characterController.Move).

Then why post?

@Achie1 have you confirmed it’s the rotation that’s the cause, and not something else? The character controller component isn’t really affected by rotation anyway. Something else may be influencing the transform perhaps.

Yes, because when I comment the line above, jumps height are the same but there is no Rotation too.

Perhaps move the character onto a child game object of the character controller and rotate that instead.

Thanks, I will try