Here’s a more precise explanation:
1/ You have a class called PlayerController, that extends CharacterBody2D. This class doesn’t do anything visual, it’s purely made for movement (since that’s what CharacterBody2D is made for).
Something like this:
extends CharacterBody2D
class_name PlayerController
func _physics_process(delta: float) -> void:
direction = Input.get_axis("go_left", "go_right")
–
2/ You want to display a sprite for your player, so in your tree, you added a node of type Sprite2D, and you defined a texture to use.
Something like this, I guess:
–
3/ When moving, based on the direction, you want to flip the sprite. To do so, you first need a reference to it, by exporting the variable:
extends CharacterBody2D
class_name PlayerController
@export var sprite: Sprite2D
func _physics_process(delta: float) -> void:
direction = Input.get_axis("go_left", "go_right")
and then assigning the node inside the Inspector.
–
4/ Now that you have a reference to your sprite, you can access it and change its flip_h value.
extends CharacterBody2D
class_name PlayerController
@export var sprite: Sprite2D
func _physics_process(delta: float) -> void:
direction = Input.get_axis("go_left", "go_right")
if direction == 1:
sprite.flip_h = false
elif direction == -1:
sprite.flip_h = true
And that should do the job.
I think you got a bit lost with how scripts work, but basically you just extend the type of your node (here, CharacterBody2D), and then you export the other nodes you want to change along the way.
What we were concerned about is that you exported a PlayerController type, while already being inside the PlayerController script (which is valid from a pure code perspective, but does not make sense in your case).
Let me know if that helps. 