I tried to flip the Sprite with the cursor position but I got something that I didn't want because now the sprite that I installed this code was rotating, the result I wanted was to just flip it left and right.
for a context, I give a video and the code I made
My current code
extends KinematicBody2D
var velocity = Vector2(0,0)
const movementspeed = 800
const playergravity = 40
const jumpforce = -1600
func _physics_process(delta):
if Input.is_action_pressed("ingame_left"):
velocity.x = -movementspeed
$AnimatedSprite.play("walk")
elif Input.is_action_pressed("ingame_right"):
velocity.x = movementspeed
$AnimatedSprite.play("walk")
else:
$AnimatedSprite.play("idle")
if not is_on_floor():
$AnimatedSprite.play("jump")
velocity.y = velocity.y + playergravity
if Input.is_action_just_pressed("ingame_jump") and is_on_floor():
velocity.y = jumpforce
velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,1)
look_at(get_global_mouse_position())
if get_global_mouse_position() <= self.global_position:
$AnimatedSprite.flip_v = true
else:
$AnimatedSprite.flip_v = false