Advertisement
RealSight

godot 4.2.1 player animations & direction

Apr 8th, 2024 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends AnimatedSprite2D
  2.  
  3. class_name PlayerAnims
  4.  
  5. func trigger_animation(velocity: Vector2, direction: int):
  6.     if not get_parent().is_on_floor():
  7.         play("jump")
  8.     elif Input.is_action_just_released("jump"):
  9.         play("fall")
  10.     # Handle slide animations
  11.     elif sign(velocity.x) != sign(direction) && velocity.x != 0 && direction != 0:
  12.         play("damp")
  13.         scale.x = direction
  14.     else:
  15.     # Handle sprite direction
  16.         if scale.x == 1 && sign(velocity.x) == -1:
  17.             scale.x = -1
  18.         elif scale.x == -1 && sign(velocity.x) == 1:
  19.             scale.x = 1
  20.     # Handle run and idle animations
  21.         if velocity.x != 0:
  22.             play("walk")
  23.         elif velocity.x < 1 && not Input.is_action_just_pressed("jump") && HealthManager.current_health > 0:
  24.             play("idle")
  25.     # Handle death animation
  26.         if HealthManager.current_health <= 0:
  27.             play("death")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement