So, I have a simple character controller that moves the player, apply gravity and rotate the player as rotate the camera. The Black Line represents the normal behavior. The Yellow Line represents my problem. And the Green Line is my desired behavior.
Besides the Yellow Line problem, I have another problem that the player is sticking to the wall while the player is the air and moving towards the wall. I already tried to put a Physics material with no friction, but it didn`t work.
So, when the player is going towards the wall and is colliding, when I press jump, the player gain some extra movement and goes higher and farther than expected (Yellow Line).
When I jump without colliding with the wall (Black Line), the max Height and max Distance are fine. They are the same values when the player is Idle (not moving) and press Jump.
My expected behavior is the Green Line. When colliding the wall and moving towards the wall, the max height value must be the same as jumping without colliding.
Here is my CharacterController code:
private void Update() {
Vector3 moveDirection = _playerInput.Movement;
//Just check if running, sprinting or idle
CheckMoveState(moveDirection);
if (moveState != MoveState.Idle) {
_characterController.transform.rotation = Quaternion.Euler(0, Camera.main.transform.eulerAngles.y, 0);
}
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= GetMoveSpeed();
if (_characterController.isGrounded) {
if (_playerInput.Jump) {
moveDirection.y = jumpSpeed;
}
}
else {
moveDirection.y = _characterController.velocity.y;
}
moveDirection.y -= gravity * Time.deltaTime;
_characterController.Move(moveDirection * Time.deltaTime);
}
Can someone help me with my 2 problems?
1 - Yellow Line problem
2 - Player stuck in wall while in the air and moving towards the wall