using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;

namespace Rokojori
{
  [GlobalClass,Tool]
  public partial class Pig:Node
  {
    [Export]
    public Node3D player;

    [Export]
    public RigidBody3D rigidBody3D;

    [Export]
    public float speed = 5;

    public override void _Process( double delta )
    {
      if ( player == null )
      {
        player = Unique<Player>.Get();
      }

      if ( player == null )
      {
        return;
      }

      if ( Engine.IsEditorHint() )
      {
        return;
      }

      var direction = player.GlobalPosition - rigidBody3D.GlobalPosition;
      direction.Y = 0;

      direction = direction.Normalized() * speed;

      rigidBody3D.GlobalPosition += direction;
      rigidBody3D.LookAt( player.GlobalPosition );
    }
  }
}