0 votes

I'm having this problem where my sprite is scaled incorrectly. I am using a sprite node, and the problem occurred when I added a script. How do I fix this?

extends KinematicBody2D

var velocity = Vector2.ZERO
export (int) var speed = 1200
export (int) var jump_speed = -1800
export (int) var gravity = 4000
export (float, 0, 1.0) var friction = 0.1
export (float, 0, 1.0) var acceleration = 0.25

var facing_right = true

## Player Movements
func get_input():
velocity.x = 0
if Input.is_action_pressed("ui_right"):
    velocity.x += speed
    facing_right = true
if Input.is_action_pressed("ui_left"):
    velocity.x -= speed
    facing_right = false

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

func _physics_process(delta):
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if Input.is_action_just_pressed("ui_up"):
    if is_on_floor():
        velocity.y = jump_speed

My Problem

Godot version 3.2.2
in Engine by (25 points)
edited by

Could you provide some information? What's the settings of the node you're using? Any other nodes involved? Btw, the image isn't showing up.

1 Answer

0 votes
Best answer

As @Ertain mentioned above, your pic link isn't working (it's a local link of your machine). In any case, be sure to check the animation's keyframes, see if there's any that changes the scale.

Also, since facing_right is already a boolean type, you don't need to use if facing_right == true,use this instead: if facing_right

by (294 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.