Advertisement
chris33556

beat-em up script (updated 15/08/22)

Aug 14th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. var velocity = Vector3.ZERO
  4. var speed = 2
  5. var isAttacking = false
  6.  
  7. onready var animatedSprite = AnimatedSprite
  8.  
  9. func _physics_process(delta):
  10. var input_vector = Vector3.ZERO
  11. input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  12. input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
  13. input_vector = input_vector.normalized()
  14.  
  15. if input_vector != Vector3.ZERO:
  16. velocity.x = input_vector.x * speed
  17. velocity.z = input_vector.z * -speed
  18. $AnimatedSprite3D.play("walk")
  19.  
  20. elif Input.is_action_just_pressed("attack"):
  21. $AnimatedSprite3D.play("punch")
  22. isAttacking = true
  23.  
  24. else:
  25. # velocity = velocity.move_toward(Vector3.ZERO, friction * delta)
  26. velocity.x = lerp(velocity.x,0,0.2)
  27. velocity.z = lerp(velocity.z,0,0.2)
  28. $AnimatedSprite3D.play("idle")
  29. isAttacking == false
  30.  
  31. # if velocity.x > 0:
  32. # animatedSprite.flip_h = false
  33. # elif velocity.x < 0:
  34. # animatedSprite.flip_h = true
  35.  
  36.  
  37.  
  38.  
  39. velocity = move_and_slide(velocity)
  40.  
  41.  
  42.  
  43.  
  44. func _on_AnimatedSprite3D_animation_finished():
  45. if $AnimatedSprite3D.animation == "punch":
  46. $AnimatedSprite3D.play("idle")
  47. isAttacking = false
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement