Advertisement
chris33556

beat-em up script 31_08_22

Aug 31st, 2022 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AS = $AnimatedSprite3D
  4. var velocity = Vector3()
  5. export var speed = 3
  6. export var gravity = 20
  7. export var jump = 7
  8. var isAttacking = false
  9.  
  10.  
  11.  
  12.  
  13. func _process(delta):
  14. _is_on_floor()
  15. var input_vector = Vector3.ZERO
  16. if is_on_floor():
  17. input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  18. input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
  19. input_vector = input_vector.normalized()
  20.  
  21.  
  22. if input_vector != Vector3.ZERO:
  23. velocity.x = input_vector.x * speed
  24. velocity.z = input_vector.z * -speed
  25. AS.play("walk")
  26. isAttacking = false
  27.  
  28.  
  29.  
  30. elif Input.is_action_pressed("attack") and is_on_floor():
  31. AS.play("punch")
  32.  
  33. elif AS.animation == "punch" and $AnimatedSprite3D.frame !=2:
  34. return
  35.  
  36.  
  37.  
  38. else:
  39. if not is_on_floor():
  40. velocity.y -= gravity * delta
  41. # if Input.is_action_pressed("ui_right"):
  42. velocity.z = 0
  43. isAttacking = false
  44.  
  45.  
  46.  
  47. else:
  48. velocity.x = 0
  49. velocity.y = 0
  50. AS.play("idle")
  51. isAttacking = false
  52.  
  53.  
  54. if input_vector.x > 0:
  55. $AnimatedSprite3D.flip_h = false
  56. scale.x = 1
  57. elif input_vector.x < 0:
  58. $AnimatedSprite3D.flip_h = false
  59. scale.x = - 1
  60.  
  61.  
  62.  
  63. func _is_on_floor():
  64. if Input.is_action_pressed("jump") and is_on_floor():
  65. velocity.y = jump
  66. velocity.z = 0
  67. AS.play("jump")
  68. isAttacking = false
  69.  
  70. velocity = move_and_slide(velocity, Vector3.UP)
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement