Advertisement
chopical

player animate

Apr 15th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var velocity = Vector2.ZERO
  4. export var SPEED = 160 #max_speed
  5. export var CELERATION=80
  6. onready var animationPlayer = $AnimationPlayer
  7. var animationPosition=0
  8.  
  9. func _physics_process(delta):
  10.     var input_vector = Vector2.ZERO
  11.     input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  12.     input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
  13.     anim(input_vector)
  14.     input_vector = input_vector.normalized()
  15.     if input_vector != Vector2.ZERO:
  16.         velocity = velocity.move_toward(input_vector*SPEED,CELERATION*delta)
  17.     else:
  18.         velocity = velocity.move_toward(Vector2.ZERO,4+CELERATION*delta)
  19.     velocity = move_and_slide(velocity)
  20.  
  21. func anim(State):
  22.     match State:
  23.         Vector2.ZERO:
  24.             if animationPosition%2:
  25.                     animationPosition-=1
  26.         Vector2(0,1):
  27.             animationPosition=1
  28.         Vector2(0,-1):
  29.             animationPosition=7
  30.         Vector2(1,0):
  31.             animationPosition=5
  32.         Vector2(-1,0):
  33.             animationPosition=3
  34.            
  35.     match animationPosition:
  36.         0:
  37.             animationPlayer.play("Idle_Down")
  38.         1:
  39.             animationPlayer.play("Run_Down")
  40.         2:
  41.             animationPlayer.play("Idle_Left")
  42.         3:
  43.             animationPlayer.play("Run_Left")
  44.         4:
  45.             animationPlayer.play("Idle_Right")
  46.         5:
  47.             animationPlayer.play("Run_Right")
  48.         6:
  49.             animationPlayer.play("Idle_Up")
  50.         7:
  51.             animationPlayer.play("Run_Up")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement