Thank you very much for the answer. It worked!
However, I wanted to play running_backward animation, when player is moving left(backward) and the mouse cursor is at right(forward).
something like this? how do I find that mouse position is opposite to the movement direction of the player ?
var is_running_backward := is_on_floor() and not is_zero_approx(_velocity.x) and "when the mouse position is opposite direction of the movement?"
my current code is like this.
func _physics_process(delta: float) -> void:
var _horizontal_direction = (
Input.get_action_strength("move_right")
- Input.get_action_strength("move_left")
)
_velocity.x = _horizontal_direction * speed
_velocity.y += gravity * delta
var is_falling := _velocity.y > 0.0 and not is_on_floor()
var is_jumping := Input.is_action_just_pressed("jump") and is_on_floor()
var is_double_jumping := Input.is_action_just_pressed("jump") and is_falling
var is_jump_cancelled := Input.is_action_just_released("jump") and _velocity.y < 0.0
var is_idling := is_on_floor() and is_zero_approx(_velocity.x)
var is_running := is_on_floor() and not is_zero_approx(_velocity.x)
var is_running_backward := is_on_floor() and not is_zero_approx(_velocity.x) and
if is_jumping:
_jumps_made += 1
_velocity.y = -jump_strength
elif is_double_jumping:
_jumps_made += 1
if _jumps_made <= maximum_jumps:
_velocity.y = -double_jump_strength
elif is_jump_cancelled:
_velocity.y = 0.0
elif is_idling or is_running:
_jumps_made = 0
_velocity = move_and_slide(_velocity, UP_DIRECTION)
if get_global_mouse_position().x > $Position2D/PlayerSkin.global_position.x:
print("right")
position2D.scale.x=1
else:
print("left")
position2D.scale.x=-1