Advertisement
chris33556

beat-em up script (updated 25/06/22)

Jun 25th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. var velocity = Vector3(0,0,0)
  4. const SPEED = 2
  5.  
  6. onready var animatedSprite = $AnimatedSprite3D
  7.  
  8. func _physics_process(delta):
  9.  
  10. if Input.is_action_pressed("ui_right") and Input.is_action_pressed("ui_left"):
  11. velocity.x = 0
  12. elif Input.is_action_pressed("ui_right"):
  13. velocity.x = SPEED
  14. animatedSprite.animation = "Walk"
  15. elif Input.is_action_pressed("ui_left"):
  16. velocity.x = -SPEED
  17. animatedSprite.animation = "Walk"
  18. else:
  19. velocity.x = lerp(velocity.x,0,0.1)
  20. animatedSprite.animation = "Idle"
  21.  
  22. if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
  23. velocity.z = 0
  24. elif Input.is_action_pressed("ui_up"):
  25. velocity.z = -SPEED
  26. animatedSprite.animation = "Walk"
  27. elif Input.is_action_pressed("ui_down"):
  28. velocity.z = SPEED
  29. animatedSprite.animation = "Walk"
  30. else:
  31. velocity.z = lerp(velocity.z,0,0.1)
  32.  
  33. if velocity.x > 0:
  34. animatedSprite.flip_h = false
  35. elif velocity.x < 0:
  36. animatedSprite.flip_h = true
  37.  
  38.  
  39. move_and_slide(velocity)
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement