moving_enemy.gd 683 B

1234567891011121314151617181920212223242526272829
  1. extends KinematicBody2D
  2. export var speed = 150.0
  3. export var velocity = Vector2(-1, 0)
  4. var dead = false
  5. var armor_type = 100 # The type of monster
  6. const player_class = preload("res://Scripts/player.gd")
  7. func _fixed_process(delta):
  8. move(velocity * delta)
  9. if (is_colliding()):
  10. if (get_collider() != null):
  11. if (get_collider() extends player_class):
  12. get_collider().stamina -= 100
  13. var a = velocity.angle_to(get_collision_normal())
  14. velocity = - velocity.rotated(2*a)
  15. move(velocity * delta)
  16. velocity = velocity.normalized() * speed
  17. if (dead):
  18. queue_free()
  19. func _ready():
  20. set_fixed_process(true)