Advertisement
chris33556

stunned_test_20th_feb

Feb 19th, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AnimSprite = $AnimatedSprite3D
  4.  
  5. var velocity = Vector3()
  6. var speed = 7
  7. var isAttacking = false
  8. var isJumping = false
  9. var jump_impulse = 300
  10. var input_vector = Vector3.ZERO
  11. onready var AttackArea = $AttackArea
  12. export (int) var damage := 10
  13. var canMove = false
  14. var AttackPoints = 2
  15.  
  16. var timer = null
  17. var crouch_delay = 0.5
  18. var isCrouch = true
  19. var current_animation
  20.  
  21. func _ready():
  22. $attackArea/CollisionShape.disabled = true
  23.  
  24. func _process(delta):
  25. if not isAttacking:
  26. velocity.x = speed * Input.get_axis("ui_left", "ui_right")
  27. velocity.z = speed * Input.get_axis("ui_up", "ui_down")
  28. AnimSprite.play("walking")
  29.  
  30. if velocity.x == 0 and velocity.z == 0:
  31. AnimSprite.play("idle")
  32. isAttacking = false
  33. if isAttacking:
  34. $attackArea/CollisionShape.disabled = true
  35. if Input.is_action_just_pressed("attack") && AttackPoints == 3:
  36. $AttackResetTimer.start()
  37. velocity.x = 0
  38. velocity.z = 0
  39. $AnimatedSprite3D.play("Attack_1")
  40. AttackPoints = AttackPoints - 1
  41. $attackArea/CollisionShape.disabled = false
  42. isAttacking = true
  43.  
  44. elif Input.is_action_just_pressed("attack") && AttackPoints == 2:
  45. $AttackResetTimer.start()
  46. velocity.x = 0
  47. velocity.z = 0
  48. $AnimatedSprite3D.play("Attack_2")
  49. AttackPoints = AttackPoints - 1
  50. $attackArea/CollisionShape.disabled = false
  51. isAttacking = true
  52. elif Input.is_action_just_pressed("attack") && AttackPoints == 1:
  53. $AttackResetTimer.start()
  54. velocity.x = 0
  55. velocity.z = 0
  56. $AnimatedSprite3D.play("Attack_3")
  57. AttackPoints = AttackPoints - 1
  58. $attackArea/CollisionShape.disabled = false
  59. isAttacking = true
  60. elif isAttacking == false:
  61. speed = 3
  62.  
  63. velocity = move_and_slide(velocity, Vector3.UP * delta)
  64. var motion = velocity.normalized() * speed
  65.  
  66.  
  67. func _on_AnimatedSprite3D_animation_finished():
  68. if $AnimatedSprite3D.animation == "Attack_1":
  69. $AnimatedSprite3D.play("idle")
  70. elif $AnimatedSprite3D.animation == "Attack_2":
  71. $AnimatedSprite3D.play("idle")
  72. elif $AnimatedSprite3D.animation == "Attack_3":
  73. $AnimatedSprite3D.play("idle")
  74. isAttacking = false
  75.  
  76.  
  77.  
  78.  
  79. func _on_AttackResetTimer_timeout():
  80. AttackPoints = 3
  81.  
  82. func _on_attackArea_body_entered(body):
  83. if body.has_method("knockback"):
  84. body.knockback(damage)
  85. if body.health > 0:
  86. if AnimSprite.animation == "Attack_1" or AnimSprite.animation == "Attack_2":
  87. body.state = body.states.STUNNED
  88. yield(get_tree().create_timer(0.5), "timeout")
  89. body.state = body.states.IDLE
  90. if body.health <= 0:
  91. body.state = body.states.KNOCKBACK
  92. yield(get_tree().create_timer(0.5), "timeout")
  93. $CollisionShape.disabled = true
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement