コード例 #1
0
    public Vector2 CalculateBehind()
    {
        Vector2 targetVel = leader.GeRightVector() * -1;

        targetVel = targetVel.normalized * leader.GetBehindLength();

        return(leader.GetPosition() + targetVel);
    }
コード例 #2
0
    private Vector3 doPursue(IBoid target)
    {
        Vector3 distance = target.GetPosition() - host.GetPosition();
        float   updates  = distance.magnitude / host.GetMaxVelocity();
        Vector3 tv       = target.GetVelocity();

        tv = this.ScaleBy(tv, updates);
        Vector3 targetFuture = target.GetPosition() + tv;

        return(doSeek(targetFuture, 10f));
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        steering.seek(endzone.GetPosition());
        //steering.evade(defense);

        steering.update();

        gameObject.transform.position = steering.position + steering.velocity;
    }
コード例 #4
0
    public void update()
    {
        velocity = host.GetVelocity();

        position = host.GetPosition();

        steering = new Vector3(
            Mathf.Clamp(steering.x, -host.GetMaxVelocity(), host.GetMaxVelocity()),
            Mathf.Clamp(steering.y, -host.GetMaxVelocity(), host.GetMaxVelocity()),
            Mathf.Clamp(steering.z, -host.GetMaxVelocity(), host.GetMaxVelocity())
            );

        velocity += steering;

        velocity = new Vector3(
            Mathf.Clamp(velocity.x, -host.GetMaxVelocity(), host.GetMaxVelocity()),
            Mathf.Clamp(velocity.y, -host.GetMaxVelocity(), host.GetMaxVelocity()),
            Mathf.Clamp(velocity.z, -host.GetMaxVelocity(), host.GetMaxVelocity())
            );

        position += velocity;
    }
コード例 #5
0
 public Vector3 Follow(Vector3 leader)
 {
     return((leader - boid.GetPosition()).normalized * boid.GetMaxVelocity());
 }
コード例 #6
0
    public static Vector2 Seek(IBoid boid, Vector2 position)
    {
        var desiredVelocity = (position - boid.GetPosition()).normalized * boid.GetMaxVelocity();

        return(desiredVelocity - boid.GetVelocity());
    }