Advertisement
chris33556

most recent player script

Mar 5th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AnimSprite = $AnimatedSprite3D
  4.  
  5. var velocity = Vector3()
  6. var speed = 3
  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 = 3
  15. var health := 50
  16. var foo : int = 10
  17. var timer = null
  18. var crouch_delay = 0.5
  19. var isCrouch = true
  20. var current_animation
  21.  
  22. enum states {
  23. IDLE,
  24. WALK,
  25. ATTACK1,
  26. ATTACK2,
  27. ATTACK3,
  28. STUNNED
  29. }
  30.  
  31. var player_state = states.IDLE
  32.  
  33. var state = 0
  34.  
  35.  
  36.  
  37. func _ready():
  38. $attackArea/CollisionShape.disabled = true
  39.  
  40.  
  41. func _physics_process(delta):
  42. get_input()
  43. update_animation()
  44. combo()
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. func get_input():
  52. if not isAttacking:
  53. velocity.x = speed * Input.get_axis("ui_left", "ui_right")
  54. velocity.z = speed * Input.get_axis("ui_up", "ui_down")
  55. player_state = states.WALK
  56.  
  57. if velocity.x == 0 and velocity.z == 0:
  58. player_state = states.IDLE
  59. isAttacking = false
  60.  
  61. velocity = move_and_slide(velocity, Vector3.UP)
  62. var motion = velocity.normalized() * speed
  63.  
  64. func combo():
  65. if isAttacking:
  66. $attackArea/CollisionShape.disabled = true
  67. if Input.is_action_just_pressed("attack") && AttackPoints == 3:
  68. $AttackResetTimer.start()
  69. velocity.x = 0
  70. velocity.z = 0
  71. player_state = states.ATTACK1
  72. AttackPoints = AttackPoints - 1
  73. $attackArea/CollisionShape.disabled = false
  74. isAttacking = true
  75.  
  76. elif Input.is_action_just_pressed("attack") && AttackPoints == 2:
  77. $AttackResetTimer.start()
  78. velocity.x = 0
  79. velocity.z = 0
  80. player_state = states.ATTACK2
  81. AttackPoints = AttackPoints - 1
  82. $attackArea/CollisionShape.disabled = false
  83. isAttacking = true
  84. elif Input.is_action_just_pressed("attack") && AttackPoints == 1:
  85. $AttackResetTimer.start()
  86. velocity.x = 0
  87. velocity.z = 0
  88. player_state = states.ATTACK3
  89. AttackPoints = AttackPoints - 1
  90. $attackArea/CollisionShape.disabled = false
  91. isAttacking = true
  92. elif isAttacking == false:
  93. speed = 1.5
  94.  
  95. velocity = move_and_slide(velocity, Vector3.UP)
  96. var motion = velocity.normalized() * speed
  97.  
  98.  
  99. func update_animation():
  100. match state:
  101. states.IDLE:
  102. $AnimatedSprite3D.play("idle")
  103. states.WALK:
  104. $AnimatedSprite3D.play("walking")
  105. states.ATTACK1:
  106. $AnimatedSprite3D.play("Attack_1")
  107. states.ATTACK2:
  108. $AnimatedSprite3D.play("Attack_2")
  109. states.ATTACK3:
  110. $AnimatedSprite3D.play("Attack_3")
  111. states.STUNNED:
  112. $AnimatedSprite3D.play("stunned")
  113.  
  114. func _on_AttackResetTimer_timeout():
  115. AttackPoints = 3
  116.  
  117.  
  118. func _on_AnimatedSprite3D_animation_finished():
  119. if $AnimatedSprite3D.animation == "Attack_1":
  120. $AnimatedSprite3D.play("idle")
  121. elif $AnimatedSprite3D.animation == "Attack_2":
  122. $AnimatedSprite3D.play("idle")
  123. elif $AnimatedSprite3D.animation == "Attack_3":
  124. $AnimatedSprite3D.play("idle")
  125. isAttacking = false
  126.  
  127.  
  128. # THIS IS THE ENEMYS KNOCKBACK FUNCTION WITH PLAYERS CODE TO REGISTER THE ATTACKS-----
  129. func _on_attackArea_body_entered(body):
  130. if body.has_method("Enemyknockback"):
  131. body.Enemyknockback(damage)
  132. if body.health > 0:
  133. if AnimSprite.animation == "Attack_1" or AnimSprite.animation == "Attack_2":
  134. if body.state != body.states.KNOCKBACK:
  135. if body.state != body.states.STUNNED:
  136. body.state = body.states.STUNNED
  137. yield(get_tree().create_timer(0.5), "timeout")
  138. body.state = body.states.IDLE
  139.  
  140. if AnimSprite.animation == "Attack_3":
  141. body.state = body.states.KNOCKBACK
  142. print("knockback")
  143. if body.health <= 0:
  144. body.state = body.states.FINALKNOCKBACK
  145. $CollisionShape.disabled = true
  146.  
  147. # THIS IS THE PLAYERS HITCOUNT BAR SO THE ENEMYS ATTACKS CAN REGISTER ------
  148. func playerknockback(damage: int):
  149. health -= damage
  150. print("player was hit!, current health: " + str(health))
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement