Topic was automatically imported from the old Question2Answer platform.
Asked By
Harmonikinesis
I have a variable that keeps track of which direction my player is facing. I want this variable to be at a different default values depending of the current level being played.
For example,in Level 1 he faces left by default,but I might want him to face right in Level 2.
Your variable is defined in your player script that extends a KinematicBody2D, right?
I think you should access it by simply using dot notation.
eg:
onready var player = $Player_node
func _ready():
var facing_x = player.facing_x #copy value from node
...
facing_x = -1 #change variable in function
player.facing_x = -1 #change value in node
If you change facing_x by assigning a new value, it happens only locally (within the _ready function but does not apply to the actual Player node).
Anyway if you only need to change the sprite you could simply use flip_h().
Thank you very much,this solved the problem.
I have a variable that keeps track of what direction the player is facing not only to set animations,but also because I intend to add a dash feature to my game,and want it to happen in the direction the player is currently facing,so flip_h wouldn’t be enough.