lab2
This commit is contained in:
1 parent
e2c87a9ec8
commit
8151450cdc
12 files changed
+9769
No files matched your search
@@ -0,0 +1,39 @@
|
||||
using Code.Base;
|
||||
|
||||
namespace Code.Lab2
|
||||
{
|
||||
public class Arrive : AgentBehaviour
|
||||
{
|
||||
public float targetRadius;
|
||||
public float slowRadius;
|
||||
public float timeToTarget = 0.1f;
|
||||
|
||||
public override Steering GetSteering()
|
||||
{
|
||||
var steering = new Steering();
|
||||
var direction = target.transform.position - transform.position;
|
||||
var distance = direction.magnitude;
|
||||
float targetSpeed;
|
||||
|
||||
if (distance < targetRadius)
|
||||
return steering;
|
||||
if (distance > slowRadius)
|
||||
targetSpeed = Agent.maxSpeed;
|
||||
else
|
||||
targetSpeed = Agent.maxSpeed * distance / slowRadius;
|
||||
|
||||
var desiredVelocity = direction;
|
||||
desiredVelocity.Normalize();
|
||||
desiredVelocity *= targetSpeed;
|
||||
steering.Linear = desiredVelocity - Agent.velocity;
|
||||
steering.Linear /= timeToTarget;
|
||||
|
||||
if (!(steering.Linear.magnitude > Agent.maxAcceleration)) return steering;
|
||||
|
||||
steering.Linear.Normalize();
|
||||
steering.Linear *= Agent.maxAcceleration;
|
||||
|
||||
return steering;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user