![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Karol Burdziński |
I have a problem with this approach. I have a sprite for walking and sprite for idle (both have different spritesheets attatched).
Using AnimationPlayer and AnimatrionTree (with BlendSpace1D) I’m trying to animate the player to walk into left or right. The problem is when I’m showing and hiding proper sprite. It seems that the “old” animation is “flashing” right before the animation tree updates it.
Little explanation:
- idle animation facing right
- moving player to the right ( walking sprite is shown and walk right animation is ran)
- stoping player, so idle animation facing right statrs
- moving player to the left (walking sprite is shown again but walk left animation is ran)
- stoping player ( now idle left animation is played, but right before there is a quick flash of the idle right animation).
My code:
func _physics_process(delta):
var inputVector = Vector2.ZERO
var acceleration = ACCELERATION_VAL * delta
var friction = FRICTION_VAL * delta
inputVector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
inputVector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
inputVector = inputVector.normalized()
if inputVector != Vector2.ZERO:
animationTree.set("parameters/Idle/blend_position", inputVector.x)
animationTree.set("parameters/Walk/blend_position", inputVector.x)
animationState.travel("Walk")
spriteIdle.hide()
spriteWalk.show()
velocity = velocity.move_toward(inputVector * MAX_SPEED, acceleration)
else:
animationState.travel("Idle")
spriteIdle.show()
spriteWalk.hide()
velocity = velocity.move_toward(Vector2.ZERO, friction)
velocity = move_and_slide(velocity)