using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WalkToPoint : EntityBehaviour
{
	public Vector3 target;
	public bool pauseWhenPlayerApproaches = false;
	
	bool arrived = false;
	Rigidbody body;

	void OnEnable() {
		arrived = false;
		body = GetComponent<Rigidbody>();
	}

	void FixedUpdate()
    {
		if (pauseWhenPlayerApproaches && entity.playerApproached && !Game.inCutscene)
			return;
		if (entity.isRolling) {
			entity.KeepRolling();
			return;
		}

		// TODO: if we don't get there in say 30 seconds,
		// should we consider teleporting?

		if (!arrived && entity.MoveToTarget(target, 0.2f))
			arrived = true;

		if (arrived && body.velocity.magnitude < 0.5f) {
			entity.lastGoodPosition = target;
			StopAction();
		}
	}
}
