48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace Code.Base
|
|
{
|
|
public class AgentBehaviour : MonoBehaviour
|
|
{
|
|
public float weight = 1.0f;
|
|
public GameObject target;
|
|
protected Agent Agent;
|
|
|
|
public virtual void Awake()
|
|
{
|
|
Agent = GetComponent<Agent>();
|
|
}
|
|
|
|
public virtual void Update()
|
|
{
|
|
Agent.SetSteering(GetSteering(), weight);
|
|
}
|
|
|
|
public virtual Steering GetSteering()
|
|
{
|
|
return new Steering();
|
|
}
|
|
|
|
public float MapToRange(float rotation)
|
|
{
|
|
rotation %= 360;
|
|
|
|
if (Mathf.Abs(rotation) <= 180) return rotation;
|
|
|
|
if (rotation < 0)
|
|
rotation += 360;
|
|
else
|
|
rotation -= 360;
|
|
|
|
return rotation;
|
|
}
|
|
|
|
public Vector3 GetOriAsVec(float orientation)
|
|
{
|
|
var vector = Vector3.zero;
|
|
vector.x = Mathf.Sin(orientation * Mathf.Deg2Rad) * 1;
|
|
vector.z = Mathf.Cos(orientation * Mathf.Deg2Rad) * 1;
|
|
return vector.normalized;
|
|
}
|
|
}
|
|
} |