Godot Version
Godot 4.2
Question
`I have a 2D platformer game using an AnimationNodeBlendTree to control my Jump, Fall, Run, and Idle animations. All the animations transition right away except when going from the Fall animation to the next one (Idle or Run upon landing).
In my debugging I noticed the following behaviors:
- When the player lands while running and I pause the debugger, the animation will immediately update to the Idle animation
- When the player lands while not running and I pause the debugger, the animation does not update and continues to show the fall
Here is my code for setting the animation parameters:
func _physics_process(delta):
anim_tree.advance(delta)
move_and_slide()
# Check if we are on the ground
if is_on_floor():
# Reset double jump
can_double_jump = true
# Set animation input
anim_tree.set("parameters/in_air_state/transition_request", "ground")
else:
# add gravity
velocity.y += gravity * delta
# set animation input
anim_tree.set("parameters/in_air_state/transition_request", "air")
# handle the jump
if Input.is_action_just_pressed("ui_accept"):
jump()
elif velocity.y > 0:
# we are falling
anim_tree.set("parameters/in_air/transition_request", "falling")
# handle the attack
if Input.is_action_just_pressed("jab"):
attack()
if direction:
# We have L/R inputs!
velocity.x = direction * SPEED
anim_tree.set("parameters/movement/transition_request", "run")
# potentially reverse animation if walking backwards
update_time_scale()
else:
if is_on_floor():
velocity.x = move_toward(velocity.x, 0, SPEED)
anim_tree.set("parameters/movement/transition_request", "idle")
func jump():
if is_on_floor():
# JUMP!
can_double_jump = true
velocity.y = JUMP_VELOCITY
spawn_dust()
anim_tree.set("parameters/in_air/transition_request", "jumping")
elif can_double_jump:
# JUMP!
can_double_jump = false
velocity.y = JUMP_VELOCITY
anim_tree.set("parameters/in_air/transition_request", "jumping")
func update_time_scale():
var facing_direction = get_global_mouse_position() - body.global_position
if facing_direction.x * direction < 0:
# different directions, reverse run
anim_tree.set("parameters/movement_time/scale", -1)
elif facing_direction.x * direction > 0:
# same directions, set timeScale to 1
anim_tree.set("parameters/movement_time/scale", 1)
func update_facing_direction():
# Check if mouse is to left or right of player
var difference = get_global_mouse_position() - body.global_position
if difference.x > 0:
body.scale.x = 1
gun_arm.position.x = 13
gun_arm.image.flip_v = false
elif difference.x < 0:
body.scale.x = -1
gun_arm.position.x = -13
gun_arm.image.flip_v = true
Here is AnimationNodeBlendTree:`
In my debugging, all the parameters are being set correctly, the darn thing just isn’t updating quickly for this one Fall animation.
Thanks