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
How can I make the jump consistent? Below are the scripts I am using.
In the
In PlayerControllerPlayerController 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 PlayerJumpingPlayerJumping 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);
}