When moving left while setting rotation_degrees to 0, the character starts rotating

Godot Version

Godot 3

Question

So, in my game you can pounce towards an enemy. When you do so, you change form and are rotated to point at them. The issue is that setting rotation degrees to 0 when you aren’t pouncing seems to make you spin when you move left.

if pouncing:
		if target:
			look_at(target.position)
		pounceTimer -= delta
		if pounceTimer > 0:
			Globals.iframe = true
			if target:
				velocity = (target.global_position - global_position).normalized() * POUNCE_SPED * 8
		else:
			Globals.iframe = false
			pouncing = false
			velocity = Vector2.ZERO
	else:
		rotation_degrees = 0

This is my code for flipping the character, which may have something to do with it:

var direction := Input.get_axis("left", "right")
	if direction == -1:
		transform.x.x = -1
	elif direction == 1:
		transform.x.x = 1

Change it to:

var direction := Input.get_axis("left", "right")
if direction: scale.x = direction

I am not sure that Input.get_axis("left", "right") always returns 1 and -1, if the above codes does not works then try this:

if direction: scale.x = 1.0 if direction > 0 else -1.0