Ejemplo n.º 1
0
    public override Vector2 CalculateSteering(MovingEntity vehicle)
    {
        Vector2 steeringForce = new Vector2();

        if (seek)
        {
            steeringForce += SteeringBehaviors.Seek(vehicle);
        }
        if (flee)
        {
            steeringForce += SteeringBehaviors.Flee(vehicle);
        }
        if (arrive)
        {
            steeringForce += SteeringBehaviors.Arrive(vehicle, SteeringBehaviors.Deceleration.normal);
        }
        if (separation)
        {
            steeringForce += SteeringBehaviors.Separation(vehicle) * 3;
        }
        if (pursuit)
        {
            steeringForce += SteeringBehaviors.Pursuit(vehicle);
        }

        return(steeringForce);
    }
Ejemplo n.º 2
0
    public override Vector2 CalculateSteering(MovingEntity vehicle)
    {
        Vector2 steeringForce = Vector2.zero;
        Vector2 force;

        if (separation)
        {
            force = SteeringBehaviors.Separation(vehicle) * 1.0f;
            if (AccumulateForce(vehicle, ref steeringForce, force) && force != Vector2.zero)
            {
                return(steeringForce);
            }
        }
        if (seek)
        {
            force = SteeringBehaviors.Seek(vehicle) * 1.0f;
            if (AccumulateForce(vehicle, ref steeringForce, force))
            {
                return(steeringForce);
            }
        }
        if (flee)
        {
            force = SteeringBehaviors.Flee(vehicle) * 1.0f;
            if (AccumulateForce(vehicle, ref steeringForce, force))
            {
                return(steeringForce);
            }
        }
        if (arrive)
        {
            force = SteeringBehaviors.Arrive(vehicle) * 1.0f;
            if (AccumulateForce(vehicle, ref steeringForce, force))
            {
                return(steeringForce);
            }
        }
        if (pursuit)
        {
            force = SteeringBehaviors.Pursuit(vehicle) * 1.0f;
            if (AccumulateForce(vehicle, ref steeringForce, force))
            {
                return(steeringForce);
            }
        }

        return(steeringForce);
    }
Ejemplo n.º 3
0
    private void Update()
    {
        SetFrameNeighbours();

        Vector3 SteeringForce = Steering.Pursuit(Player.Instance) * Seek;

        SteeringForce += Steering.Wander() * Wander;
        SteeringForce += Steering.Separation() * Separation;
        SteeringForce += Steering.Alignment() * Alightment;
        SteeringForce += Steering.Cohesion() * Cohesion;
        Vector3 Avoidance = Steering.ObstacleAvoidance();

        if (Avoidance.magnitude > float.Epsilon)
        {
            SteeringForce = Avoidance;
        }
        Velocity += SteeringForce * Acceleration * Time.deltaTime;
        Velocity.Truncate(MaxSpeed);
        transform.position += Velocity * Time.deltaTime;
        FixCollision();
    }