using UnityEngine;
using System.Collections;
using Game.Plugins.App.Sync;

namespace Pathfinding.Examples {
	using Pathfinding.RVO;

	/// <summary>
	/// Player controlled character which RVO agents will avoid.
	/// This script is intended to show how you can make NPCs avoid
	/// a player controlled (or otherwise externally controlled) character.
	///
	/// See: Pathfinding.RVO.RVOController
	/// </summary>
	[RequireComponent(typeof(RVOController))]
	[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_manual_r_v_o_agent.php")]
	public class ManualRVOAgent : JNGSyncFrameDefault {
		RVOController rvo;

		public float speed = 1;

		void Awake () {
			rvo = GetComponent<RVOController>();
		}

		public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
		{
			base.OnSyncUpdate(dt, frame, input);
			var x = Input.GetAxis("Horizontal");
			var y = Input.GetAxis("Vertical");

			var v = new Vector3(x, 0, y) * speed;

			// Override the RVOController's velocity. This will disable local avoidance calculations for one simulation step.
			rvo.velocity = v;
			transform.position += v * GetSync().Time.deltaTime;
		}
	}
}
