39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Code.Base;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Lab3
|
|
{
|
|
public class Wander : Face
|
|
{
|
|
public float offset;
|
|
public float radius;
|
|
public float rate;
|
|
|
|
public override void Awake()
|
|
{
|
|
target = new GameObject
|
|
{
|
|
transform =
|
|
{
|
|
position = transform.position
|
|
}
|
|
};
|
|
base.Awake();
|
|
}
|
|
|
|
public override Steering GetSteering()
|
|
{
|
|
var wanderOrientation = Random.Range(-1f, 1f) * rate;
|
|
var targetOrientation = wanderOrientation + Agent.orientation;
|
|
var orientationVec = GetOriAsVec(Agent.orientation);
|
|
var targetPosition = offset * orientationVec + transform.position;
|
|
targetPosition += GetOriAsVec(targetOrientation) * radius;
|
|
TargetAux.transform.position = targetPosition;
|
|
var steering = base.GetSteering();
|
|
steering.Linear = TargetAux.transform.position - transform.position;
|
|
steering.Linear.Normalize();
|
|
steering.Linear *= Agent.maxAcceleration;
|
|
return steering;
|
|
}
|
|
}
|
|
} |