25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. extends KinematicBody
  2. # stats
  3. var curHp : int = 3
  4. var maxHp : int = 3
  5. # attacking
  6. var damage : int = 1
  7. var attackDist : float = 1.5
  8. var attackRate : float = 1.0
  9. # physics
  10. var moveSpeed : float = 2.5
  11. var gravity : float = 15.0
  12. # vectors
  13. var vel : Vector3 = Vector3()
  14. # components
  15. onready var timer = get_node("Timer")
  16. export var player_path : NodePath
  17. onready var player = get_node(player_path)
  18. onready var anim = get_node("Zombie_Male/AnimationPlayer")
  19. func _ready ():
  20. # set the timer wait time
  21. timer.wait_time = attackRate
  22. timer.start()
  23. # called every "attackRate" seconds
  24. func _on_Timer_timeout ():
  25. # if we're within the attack distance - attack the player
  26. if translation.distance_to(player.translation) <= attackDist:
  27. anim.play("Punch")
  28. player.take_damage(damage)
  29. # called 60 times a second
  30. func _physics_process (delta):
  31. # get the distance from us to the player
  32. var dist = translation.distance_to(player.translation)
  33. # if we're outside of the attack distance, chase after the player
  34. if dist > attackDist:
  35. # calculate the direction between us and the player
  36. var dir = (player.translation - translation).normalized()
  37. vel.x = dir.x
  38. vel.z = dir.z
  39. # gravity
  40. vel.y -= gravity * delta
  41. # TODO better
  42. look_at(player.translation, Vector3.UP)
  43. rotation_degrees.x = 0
  44. rotation_degrees.y = rotation_degrees.y + 180
  45. rotation_degrees.z = 0
  46. # move towards the player
  47. vel = move_and_slide(vel, Vector3.UP)
  48. if is_on_floor():
  49. if anim.current_animation != "Punch" and anim.current_animation != "RecieveHit":
  50. if vel.length_squared() > 0:
  51. anim.play("Walk")
  52. else:
  53. anim.play("Idle")
  54. else:
  55. anim.play("RecieveHit")
  56. # called when the player deals damage to us
  57. func take_damage (damageToTake):
  58. curHp -= damageToTake
  59. anim.play("RecieveHit")
  60. # if our health reaches 0 - die
  61. if curHp <= 0:
  62. die()
  63. # called when our health reaches 0
  64. func die ():
  65. # destroy the node
  66. queue_free()