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,58 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Agent : MonoBehaviour
|
||||
{
|
||||
public float maxSpeed;
|
||||
public float maxAccel;
|
||||
public float maxRotation;
|
||||
public float maxAngularAccel;
|
||||
public float orientation;
|
||||
public float rotation;
|
||||
public Vector3 velocity;
|
||||
protected Steering steering;
|
||||
|
||||
void Start()
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
steering = new Steering();
|
||||
}
|
||||
|
||||
public void SetSteering(Steering steering)
|
||||
{
|
||||
this.steering = steering;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
Vector3 displacement = velocity * Time.deltaTime;
|
||||
orientation += rotation * Time.deltaTime;
|
||||
if (orientation < 0.0f)
|
||||
orientation += 360.0f;
|
||||
else if (orientation > 360.0f)
|
||||
orientation -= 360.0f;
|
||||
transform.Translate(displacement, Space.World);
|
||||
transform.rotation = new Quaternion();
|
||||
transform.Rotate(Vector3.up, orientation);
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
velocity += steering.linear * Time.deltaTime;
|
||||
rotation += steering.angular * Time.deltaTime;
|
||||
if (velocity.magnitude > maxSpeed)
|
||||
{
|
||||
velocity.Normalize();
|
||||
velocity = velocity * maxSpeed;
|
||||
}
|
||||
if (steering.angular == 0.0f)
|
||||
{
|
||||
rotation = 0.0f;
|
||||
}
|
||||
if (steering.linear.sqrMagnitude == 0.0f)
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
}
|
||||
steering = new Steering();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user