func _ready ():
# set the timer wait time
timer.wait_time = attackRate
timer.start()
# called 60 times a second
func _physics_process (_delta):
# get the distance from us to the player
var dist = position.distance_to(player.position)
# if we're outside of the attack distance, chase after the player
if dist > attackDist:
# calculate the direction between us and the player
var dir = (player.position - position).normalized()
velocity.x = dir.x
velocity.y = 0
velocity.z = dir.z
# move towards the player
move_and_slide()
look_at(transform.origin - velocity, Vector3.UP)
# called every "attackRate" seconds
func on_timeout():
# if we're within the attack distance - attack the player
if position.distance_to(player.position) <= attackDist:
weapon.try_attack("Player", damage)
# player.take_damage(damage)
# called when the player deals damage to us
func take_damage (damageToTake):
curHp -= damageToTake
# if our health reaches 0 - die
if curHp <= 0:
die()
# called when our health reaches 0
func die ():
# destroy the node
queue_free()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}