Files

47 lines
1.6 KiB
C#
Raw Permalink Normal View History

2026-03-19 02:02:28 +03:00
using UnityEngine;
using System.Collections;
public class Wander : Face
{
public float offset;
public float radius;
public float rate;
public override void Awake()
{
target = new GameObject();
target.transform.position = transform.position;
base.Awake();
}
public override Steering GetSteering()
{
Steering steering = new Steering();
float wanderOrientation = Random.Range(-1.0f, 1.0f) * rate;
float targetOrientation = wanderOrientation + agent.orientation;
2026-03-20 00:22:54 +03:00
// Вычисляем позицию цели для поворота
2026-03-19 02:02:28 +03:00
Vector3 orientationVec = GetOriAsVec(agent.orientation);
Vector3 targetPosition = (offset * orientationVec) + transform.position;
targetPosition = targetPosition + (GetOriAsVec(targetOrientation) * radius);
2026-03-20 00:22:54 +03:00
// Передаем позицию цели в Face для расчета поворота
2026-03-19 02:02:28 +03:00
targetAux.transform.position = targetPosition;
2026-03-20 00:22:54 +03:00
// Получаем только поворот от Face
2026-03-19 02:02:28 +03:00
steering = base.GetSteering();
2026-03-20 00:22:54 +03:00
// Добавляем постоянное движение вперед
steering.linear = agent.maxAccel * GetOriAsVec(agent.orientation);
2026-03-19 02:02:28 +03:00
return steering;
}
public Vector3 GetOriAsVec(float orientation)
{
Vector3 vector = Vector3.zero;
vector.x = Mathf.Sin(orientation * Mathf.Deg2Rad) * 1.0f;
vector.z = Mathf.Cos(orientation * Mathf.Deg2Rad) * 1.0f;
return vector.normalized;
}
}