AnimationPlayer animates Node properties from key values of your choosing.
These values will remain the same even if the Node is being extensively modified in your script, so your problem as an example:
Notes about this answer for others — I have run this project's code
While the AnimationPlayer will always set the animation to the same values, if you happen to flip the parent of the animated Node by setting its
-1, from the animation's perspective it is still achieving its desired rotation but from the main scene's perspective, it looks like this:
In this case, the Sword is an instanced scene which has its own animation and is the child of the Player scene.
But since flipping the Player in this manner is undesirable, what you can do instead is add a new Node2D in the Player scene and make the Sword instance a child of it:
Naturally after doing this you will have to change all references to the Sword node to be Node2D/Sword — though in your case you have direct references to the "PlayerOne" parent (player node), so change the name of Node2D to PlayerOne and change the references to
In order to flip the Node2D, you will need to also add to the Player movement script:
$PlayerOne.scale.x = 1 (on right movement)
$PlayerOne.scale.x = -1 (on left movement)
And you'll also need to remove the code that was changing the Sword's idle rotation:
Sword.position.x = -15
Sword.rotation_degrees = -9.4
From the left movement specifically, but the code in the right channel will become redundant as well.
And for future reference, the alternative option to all this (as you had implemented as a stop-gap) is to simply create a 2nd set of reversed animations, but at some point this would become impractical to maintain.
I hope this finds you well!