Hello guys, am trying to make realistic full body first person controller (resident evil 7 like). I want to add in place turning animation, when a player moves the mouse left or right. I allready have a 2D freeform directional blend tree for my movements and I also have script that would handle the turning animation. But I don’t know what I should add in my animator to make the turn animation actually work. Could anyone help me?
this is my code:
private void HandleAnimations()
{
// Calculate velocity components for movement blend tree
float velocityX = _input.move.x * _speed / MoveSpeed;
float velocityY = _input.move.y * _speed / MoveSpeed;
// Pass these values to the Animator for movement animations
_playerAnimator.SetFloat("VelocityZ", velocityX, dampTime, Time.deltaTime);
_playerAnimator.SetFloat("VelocityY", velocityY, dampTime, Time.deltaTime);
// Check if character is moving
bool isMoving = velocityX != 0 || velocityY != 0;
// Calculate turn direction based on mouse movement only when idle
float turnDirection = 0;
if (!isMoving) // Only turn when idle
{
float mouseX = Input.GetAxis("Mouse X");
if (mouseX > 0.1f) // You can adjust the threshold here
{
turnDirection = 1; // Right turn
}
else if (mouseX < -0.1f)
{
turnDirection = -1; // Left turn
}
}
// Update the TurnDirection parameter and log it
_playerAnimator.SetFloat("TurnDirection", turnDirection, dampTime, Time.deltaTime);
Debug.Log("TurnDirection: " + turnDirection);
}
in the screenshot you can see my animator
