Godot Version
4.3
Question
I created an animal scene, and I wanted the animal to move back and forth and play the corresponding left and right animations (with tween and AnimationPlayer)
The left and right moves succeeded, but only the left animation was played (the animation itself was fine), i.e. only the last line of code except for tween could be run(I have annotations in the code)
Here’s the code:
extends StaticBody2D
var tween:Tween
@onready var animation_player: AnimationPlayer = $AnimationPlayer
var x : bool
Called when the node enters the scene tree for the first time.
func _ready() → void:
tween = get_tree().create_tween().set_loops()
animation_player.play(“right”)#This line does not run!!!!
tween.tween_property(self,“position:x”,100,2).as_relative()
#Only this line can be run, and the code that plays the animation on the right cannot be run↓↓↓↓
animation_player.play(“left”) tween.tween_property(self,“position:x”,-100,2).as_relative()
func _process(delta: float) → void:
pass
(I don’t know much English, so I translated this question)HELP ME!