Advertisement
chris33556

air_attack_WIP

Nov 8th, 2022
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AnimSprite = $AnimatedSprite3D
  4.  
  5. var velocity = Vector3(0, 0, 0)
  6. var speed = 70
  7. var isAttacking = false
  8. var isJumping = false
  9. var gravity = -10
  10. var jump_impulse = 200
  11.  
  12. onready var AttackArea = $AttackArea
  13. export (int) var damage := 10
  14.  
  15.  
  16. func _process(delta):
  17. _is_on_floor()
  18. apply_gravity()
  19. if is_on_floor() and not isAttacking:
  20. velocity.x = speed * Input.get_axis("move_left", "move_right")
  21. velocity.z = speed * Input.get_axis("move_up", "move_down")
  22. AnimSprite.play("walk2")
  23.  
  24. if velocity.x == 0 and velocity.z == 0:
  25. AnimSprite.play("idle")
  26. isAttacking == false
  27.  
  28. if Input.is_action_just_pressed("punch"):
  29. $snapPunch.play()
  30. velocity.x = 0
  31. velocity.z = 0
  32. $AnimatedSprite3D.play("punch")
  33. $AttackArea/CollisionPunch.disabled = false
  34. isAttacking = true
  35.  
  36.  
  37.  
  38. # elif Input.is_action_just_pressed("crouch"):
  39. # velocity.x = 0
  40. # velocity.z = 0
  41. # $AnimatedSprite3D.play("crouching")
  42. # isJumping = false
  43.  
  44. elif Input.is_action_just_pressed("reverse_kick"):
  45. $snapPunch.play()
  46. velocity.x = 0
  47. velocity.z = 0
  48. $AnimatedSprite3D.play("reverse_kick")
  49. $AttackArea/CollisionRearKick.disabled = false
  50. isAttacking = true
  51.  
  52.  
  53.  
  54. else:
  55. if not is_on_floor():
  56. velocity.y -= gravity * delta
  57. # if Input.is_action_pressed("ui_right"):
  58. velocity.z = 0
  59. isAttacking = false
  60.  
  61. if velocity.x > 0:
  62. AnimSprite.flip_h = false
  63. scale.x = 29
  64. elif velocity.x < 0:
  65. AnimSprite.flip_h = false
  66. scale.x = -29
  67.  
  68. func _is_on_floor():
  69. if Input.is_action_just_pressed("jump") and is_on_floor():
  70. velocity.y = jump_impulse
  71. AnimSprite.play("jumping")
  72. isAttacking = false
  73.  
  74.  
  75. elif Input.is_action_just_pressed("airAttack"):
  76. $AnimatedSprite3D.play("air_attack")
  77. $snapPunch.play()
  78. $AttackArea/CollisionAirPunch.disabled = false
  79. isAttacking = true
  80.  
  81. elif is_on_floor():
  82. $AttackArea/CollisionAirPunch.disabled = true
  83.  
  84. velocity = move_and_slide(velocity, Vector3.UP)
  85.  
  86. return velocity.normalized()
  87.  
  88. func apply_gravity():
  89. velocity.y = velocity.y + gravity
  90.  
  91.  
  92.  
  93.  
  94.  
  95. func _on_AnimatedSprite3D_animation_finished():
  96. if $AnimatedSprite3D.animation == "punch":
  97. $AttackArea/CollisionPunch.disabled = true
  98. isAttacking = false
  99.  
  100. if $AnimatedSprite3D.animation == "reverse_kick":
  101. $AttackArea/CollisionRearKick.disabled = true
  102. isAttacking = false
  103.  
  104.  
  105.  
  106. func _on_AttackArea_body_entered(body):
  107. if body.has_method("handle_hit"):
  108. body.handle_hit(damage)
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement