I’m working on a 3rd person prototype using sprites with billboarding and using Cinemachine did the camera controller and I’m trying to animate the sprites like how is done on Doom or Xenogears. I can make the character walk relative to the camera angle without issues, but animating the character based on the walk direction and camera angle isn’t working well. I’m using the Animator/Blend Tree approach with a 2D blend to make the animations so, for example, walk animation consists on a Blend Tree with 8 Animation Clips on it, like the below example:
So, using the X and Z of the direction vector I can set the animation to the character:
void GetPlayerToCamDir()
{
anim.SetFloat("X", lookDir.x);
anim.SetFloat("Y", lookDir.z);
}
8way movement without camera rotation works very well, but when taking the rotation from the camera and the movement direction, it’s just goes bonkers. This is part of the code of what I am using for movement (inside Update):
h = Input.GetAxisRaw("Horizontal");
v = Input.GetAxisRaw("Vertical");
direction = new Vector2(h, v).normalized;
if (direction.magnitude >= 0.1f) lastDirection = direction;
lookAngle = (Mathf.Atan2(lastDirection.x, lastDirection.y) * Mathf.Rad2Deg) - cam.transform.eulerAngles.y;
dirAngle = (Mathf.Atan2(lastDirection.x, lastDirection.y) * Mathf.Rad2Deg);
if (direction.magnitude >= 0.1f)
{
spd = currentSpd;
targetAngle = Mathf.Atan2(lastDirection.x, lastDirection.y) * Mathf.Rad2Deg + cam.transform.eulerAngles.y;
movDir = (Quaternion.Euler(0, targetAngle, 0) * Vector3.forward).normalized;
anim.SetBool("Walk", true);
}
else
{
spd = 0;
anim.SetBool("Walk", false);
}
spriteAngle = (targetAngle - dirAngle) - lookAngle;
lookDir = (Quaternion.Euler(0, spriteAngle, 0) * Vector3.forward).normalized;
My issues come from converting the angle of the camera and the angle of where is looking the character into a Vector3 that I can use on the Animator.
What can be done here?