I implemented the sword rotation a little differently. I tried to take the mouse position relative to the player instead of the center of the screen. This way as the player moves around the sword rotation will follow the mouse’s position relative to the player. This also seemed to help with the flipping as it created negative angles for the left side of screen.
It took me so much time to figure this out its unbelievable
I wanted it to work the same way as you describe it, but I wanted to keep -180 on y rotation. Without it, it messed up the animation (at least for me…) - it indeed gives good effect, but its not the same as it is in lecture
The way I made it work is quite similar, but I have adjusted some values:
currently unsure if this will have consequences down the line, but this added to the PlayerController script seemed to have handled this before the challenge even came up in this video.
private void Update()
{
PlayerInput(); //from earlier in the lesson
AdjustPlayerFacingDirection();
}
private void AdjustPlayerFacingDirection()
{
if (Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue()).x < transform.position.x)
{
transform.localScale = new Vector3(-1, 1, 1);
}
else
{
transform.localScale = new Vector3(1, 1, 1);
}
}