Godot Version
v4.2.1
Question
I was making a platformer game using a tutorial, it had a script that checks flip_h in the AnimatedSprite2D inspector by using the script.
I tried to use the code but it didn’t check the flip_h.
the code i was using:
var isLeft = velocity.x < 0
AnimatedSprite2D.flip_h = isLeft
i also added this at the beginning of the script after “extends CharacterBody2D”
@onready var animated_sprite_2d = $AnimatedSprite2D
the full code:
extends CharacterBody2D
@export var speed = 300
@export var gravity = 30
@export var jump_force = 700
@onready var animated_sprite_2d = $AnimatedSprite2D
func _physics_process(delta):
if !is_on_floor():
velocity.y += gravity
if velocity.y > 1000:
velocity.y = 1000
if Input.is_action_pressed("jump") and is_on_floor():
velocity.y = -jump_force
var horizontal_direction = Input.get_axis("move_left", "move_right")
velocity.x = speed * horizontal_direction
move_and_slide()
var isLeft = velocity.x < 0
animated_sprite_2d.flip_h = isLeft
edit
i accidentally deleted the post but its back