0 votes

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 physicsprocess(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

Godot version 3.3.2-3
in Engine by (12 points)

It could be hiding behind another node, maybe?

1 Answer

+1 vote

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")
by (57 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.