MontyMole.gd 581 B

1234567891011121314151617181920
  1. extends Enemy
  2. var target_player: Player = null
  3. const MOVE_SPEED := 100.0
  4. const ACCEL := 1.0
  5. func _physics_process(delta: float) -> void:
  6. target_player = get_tree().get_first_node_in_group("Players")
  7. direction = sign(target_player.global_position.x - global_position.x)
  8. $Sprite.scale.x = direction
  9. handle_movement(delta)
  10. func handle_movement(delta: float) -> void:
  11. apply_enemy_gravity(delta)
  12. if is_on_wall():
  13. velocity.x = (MOVE_SPEED / 2) * get_wall_normal().x
  14. velocity.y = -100
  15. velocity.x = lerpf(velocity.x, MOVE_SPEED * direction, delta * ACCEL)
  16. move_and_slide()