Godot version 4.2.1
My character isn’t flipping through “flip h” is on. Please help. code below
<extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
@onready var anim = get_node(“AnimationPlayer”)
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed(“ui_accept”) and is_on_floor():
velocity.y = JUMP_VELOCITY
anim.play(“jump”)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis(“ui_left”, “ui_right”)
print(direction)
if direction == -1:
get_node(“CollisionShape2D/AnimatedSprite2D”).flip_h = true
elif direction == 1:
get_node(“CollisionShape2D/AnimatedSprite2D”).flip_h = false
if direction:
velocity.x = direction * SPEED * 3
if velocity.y == 0:
anim.play("run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y == 0:
anim.play("Idel")
if velocity.y > 0:
anim.play("fall")
move_and_slide()>