Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Blackyy |
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
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?
jgodfrey | 2022-12-08 23:10
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
Blackyy | 2022-12-09 01:56