The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I'm new to Godot, and I've been having a problem recently: every time I use a node to change my sprite's direction using "A" and "D" (it's a platform game), the sprite stretches. Below are the codes I used:

func _get_input():
var move_direction = int(Input.is_action_pressed("move_right")) -   int(Input.is_action_pressed("move_left"))
velocity.x = move_speed * move_direction

if move_direction !=0:
    $texture.scale.x = move_direction

some1 help me

Godot version 3.5.1
in Engine by (12 points)

In the posted code, I assume $texture is a reference to the sprite node itself? If that's the case, I don't really see anything wrong with the code. What does your scene tree structure look like? Which node is the above script attached to? Are there any ancestor nodes that have non-standard scaling values assigned to them? Is there more related code here?

Yes! The "$texture" is my sprite node. Here is the all structure:

extends KinematicBody2D

var velocity = Vector2.ZERO
var move_speed = 480
var gravity = 1200
var jump_force = -720 / 2

func _physics_process(delta: float) -> void:
velocity.y += gravity * delta

_get_input()

if Input.is_action_pressed("jump"):
    velocity.y = jump_force


velocity = move_and_slide(velocity)

func _get_input():
var move_direction = int(Input.is_action_pressed("move_right")) -               int(Input.is_action_pressed("move_left"))
velocity.x = move_speed * move_direction

1 Answer

+1 vote

Try making the code a little more explicit and see if you still get the same error, try this for instance:

func _get_input():
    var move_direction = vector2d
    if Input.is_action_pressed("move_right"):
        move_direction.x = 1
    elif Input.is_action_pressed("move_left"):
         move_direction.x = -1
    velocity.x = move_speed * move_direction
by (3,328 points)
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.