Why does my character turn invisible while running left?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By oceanicmoth

I followed a tutorial on YouTube to make a 2d platformer and my character turns invisible whenever I run left. I’m pretty new to programming, and especially new to Godot and GDscript. here is my entire script for the character. `extends KinematicBody2D

const UP = Vector2(0,-1)
const GRAVITY = 20
const MAXFALLSPEED = 100
const MAXSPEED = 80
const JUMPFORCE = 300
const ACCEL = 10

var motion = Vector2()
var facing_right = true
func _ready():
pass

func _physics_process(delta):

motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
	motion.y = MAXFALLSPEED

if facing_right == true:
	$Sprite.scale.x = 1
else:
	$Sprite.scale.x = -1

motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED)

if Input.is_action_pressed("right"):
	motion.x += ACCEL
	facing_right = true
	$AnimationPlayer.play("running")
elif Input.is_action_pressed("left"):
	motion.x -= ACCEL
	facing_right = false
	$AnimationPlayer.play("running")
else:
	motion.x = lerp(motion.x,0,0.2)
	$AnimationPlayer.play("idle")
if is_on_floor():
	if Input.is_action_just_pressed("jump"):
		motion.y = -JUMPFORCE
if !is_on_floor():
	if motion.y < 0:
		$AnimationPlayer.play("jump")
	elif motion.y > 0:
		$AnimationPlayer.play("fall")

motion = move_and_slide(motion,UP)

`
any response is helpful. thank you

It could be hiding behind another node, maybe?

Snail0259 | 2021-08-17 05:11

:bust_in_silhouette: Reply From: abdallhhelles

Hi there,
I suggest doing it like that

Remove

if facing_right == true:
    $Sprite.scale.x = 1
else:
    $Sprite.scale.x = -1

Edit

if Input.is_action_pressed("right"):
    motion.x += ACCEL
     $Sprite.flip_h = false
    $AnimationPlayer.play("running")
elif Input.is_action_pressed("left"):
    motion.x -= ACCEL
    $Sprite.flip_h = true
    $AnimationPlayer.play("running")

hes no longer invisible but doesnt mirror. perhaps the code is in the wrong order?

oceanicmoth | 2021-08-17 23:31