scripts 1 var
This commit is contained in:
1 parent
6df424ea8e
commit
1798ac3fc5
10 files changed
+364
No files matched your search
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Align : AgentBehaviour
|
||||
{
|
||||
public float targetRadius;
|
||||
public float slowRadius;
|
||||
public float timeToTarget = 0.1f;
|
||||
|
||||
public override Steering GetSteering()
|
||||
{
|
||||
Steering steering = new Steering();
|
||||
float targetOrientation = target.GetComponent<Agent>().orientation;
|
||||
float rotation = targetOrientation - agent.orientation;
|
||||
rotation = MapToRange(rotation);
|
||||
float rotationSize = Mathf.Abs(rotation);
|
||||
if (rotationSize < targetRadius)
|
||||
return steering;
|
||||
float targetRotation;
|
||||
if (rotationSize > slowRadius)
|
||||
targetRotation = agent.maxRotation;
|
||||
else
|
||||
targetRotation = agent.maxRotation * rotationSize / slowRadius;
|
||||
targetRotation *= rotation / rotationSize;
|
||||
steering.angular = targetRotation - agent.rotation;
|
||||
steering.angular /= timeToTarget;
|
||||
float angularAccel = Mathf.Abs(steering.angular);
|
||||
if (angularAccel > agent.maxAngularAccel)
|
||||
{
|
||||
steering.angular /= angularAccel;
|
||||
steering.angular *= agent.maxAngularAccel;
|
||||
}
|
||||
return steering;
|
||||
}
|
||||
|
||||
protected float MapToRange(float rotation)
|
||||
{
|
||||
while (rotation < -180.0f)
|
||||
rotation += 360.0f;
|
||||
while (rotation > 180.0f)
|
||||
rotation -= 360.0f;
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user