Character wont face the same direction as the camera

I have followed and rewatched the code for making the character face the direction of the camera.

It seems to only want to face the left and right and won’t turn fully forward or backwards. I have checked my code with the lectures several times and it seems to be identical.

I shall include my movement and look methods from the PlayerFreeLookState just to ensure I’m not going mad '^-^

public override void Tick(float deltaTime)
    {
        Vector3 movement = CalculateMovement();

        Move(movement * stateMachine.FreeLookMovementSpeed, deltaTime);

        if (stateMachine.InputReader.MovementValue == Vector2.zero)
        {
            stateMachine.Animator.SetFloat(FreeLookSpeedHash, 0, AnimatorDampTime, deltaTime);
            return;
        }

        stateMachine.Animator.SetFloat(FreeLookSpeedHash, 1, AnimatorDampTime, deltaTime);
        FaceMovementDirection(movement, deltaTime);
    }
 private Vector3 CalculateMovement()
    {
        Vector3 forward = stateMachine.MainCameraTransform.forward;
        Vector3 right = stateMachine.MainCameraTransform.right;

        forward.y = 0;
        right.y = 0;

        forward.Normalize();
        right.Normalize();

        return forward * stateMachine.InputReader.MovementValue.y
            + right * stateMachine.InputReader.MovementValue.x;
    }
private void FaceMovementDirection(Vector2 movement, float deltaTime)
    {
        stateMachine.transform.rotation = Quaternion.Lerp(
            stateMachine.transform.rotation,
            Quaternion.LookRotation(movement),
            deltaTime * stateMachine.RotationDamping
        );
}

Any ideas or corrections would be greatly appreciated!

Thanks!

Hey @JakeMeaker . In your FaceMovementDirection you have a Vector2 movement. It should be Vector3 . Let me know if that fixes the issue.

1 Like

Yep, that fixed it!
I knew I had done something dumb :rofl:

Thank you :smiley:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms