public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        // Retrieve the amount of light energy possessed by the NPC performing this action
        float myLightEnergy = steerable.GetComponent<LightSource>().LightEnergy.CurrentEnergy;

        if (targetLightSource)
        {
            // If this fish has less light than its target
            if(!alwaysSeek && (myLightEnergy < targetLightSource.LightEnergy.CurrentEnergy || alwaysFlee))
            {
                // Flee the light source since it is stronger than this fish
                fleeWhenWeaker.Execute(steerable);

                //Debug.Log("FLEE THE FISH: " + targetLightSource.name);
            }
            // Else, if this fish has more light than its target
            else
            {
                // Seek the light source
                seekWhenStronger.Execute(steerable);
            }
        }
        else
        {
            // If the light source has been destroyed, stop performing this action.
            ActionCompleted();
        }

        wallAvoidance.Execute(steerable);
    }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetFlare)
        {
            // Override the steerable's min/max speed
            if (overrideSteerableSpeed)
            {
                steerable.MinSpeed = minSpeed;
                steerable.MaxSpeed = maxSpeed;
            }
            // Override the steerable's max force
            if (overrideMaxForce)
            {
                steerable.MaxForce = maxForce;
            }

            // Seek the light source
            arrivalForce.Execute(steerable);
        }
        else
        {
            // If the flare has been destroyed, stop seeking it
            ActionCompleted();
        }

        wallAvoidance.Execute(steerable);
    }
    public override void Execute(Steerable steerable)
    {
        Player player = targetLightSource.gameObject.GetComponent<Player>();
        if (!player.isSafe)
        {
            base.Execute(steerable);

            if (overrideSteerableSpeed)
            {
                steerable.MinSpeed = minSpeed;
                steerable.MaxSpeed = maxSpeed;
            }
            // Override the steerable's max force
            if (overrideMaxForce)
            {
                steerable.MaxForce = maxForce;
            }

            Vector3 position = targetLightSource.transform.position;
            if (overrideBossSpeed(steerable, position))
            {
                steerable.MinSpeed = speedMinIncreased;
                steerable.MaxSpeed = speedMaxIncreased;
            }
            steerable.AddSeekForce(position, strengthMultiplier);
        }
        else
        {
            ActionCompleted();
        }

        wallAvoidance.Execute(steerable);
    }
    public override void Execute(Steerable steerable)
    {
        // Override the steerable's min/max speed
        if (overrideSteerableSpeed)
        {
            steerable.MinSpeed = minSpeed;
            steerable.MaxSpeed = maxSpeed;
        }
        // Override the steerable's max force
        if (overrideMaxForce)
        {
            steerable.MaxForce = maxForce;
        }

        //checks if the boss fish is at the waypoint, if so then no need to move to waypoint anymore
        if((Vector2)bigFish.GetComponent<Rigidbody>().velocity == Vector2.zero)
        {
            ActionCompleted();
        }
        else
        {
            steerable.AddMoveWaypointForce(waypointList, bigFish, slowingRadius, strengthMultiplier);
        }

        wallAvoidance.Execute(steerable);
    }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetTransform)
        {
            // Override the steerable's min/max speed
            if (overrideSteerableSpeed)
            {
                steerable.MinSpeed = minSpeed;
                steerable.MaxSpeed = maxSpeed;
            }
            // Override the steerable's max force
            if (overrideMaxForce)
            {
                steerable.MaxForce = maxForce;
            }

            // If player's lights are on, seek player
            if (targetTransform.gameObject.CompareTag("Player"))
            {
                Player player = targetTransform.gameObject.GetComponent<Player>();
                if (player.IsDetectable())
                {
                    steerable.AddSeekForce(targetTransform.position, strengthMultiplier);
                    AkSoundEngine.PostEvent("Fish_Detection", targetTransform.gameObject);
                }
            }
            else
            {
                steerable.AddSeekForce(targetTransform.position, strengthMultiplier);
            }

        }
    }
Exemplo n.º 6
0
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetFlare)
        {
            // Override the steerable's min/max speed
            if (overrideSteerableSpeed)
            {
                steerable.MinSpeed = minSpeed;
                steerable.MaxSpeed = maxSpeed;
            }
            // Override the steerable's max force
            if (overrideMaxForce)
            {
                steerable.MaxForce = maxForce;
            }

            // Seek the light source
            arrivalForce.Execute(steerable);
        }
        else
        {
            // If the flare has been destroyed, stop seeking it
            ActionCompleted();
        }

        wallAvoidance.Execute(steerable);
    }
Exemplo n.º 7
0
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        // Retrieve the amount of light energy possessed by the NPC performing this action
        float myLightEnergy = steerable.GetComponent <LightSource>().LightEnergy.CurrentEnergy;

        if (targetLightSource)
        {
            // If this fish has less light than its target
            if (!alwaysSeek && (myLightEnergy < targetLightSource.LightEnergy.CurrentEnergy || alwaysFlee))
            {
                // Flee the light source since it is stronger than this fish
                fleeWhenWeaker.Execute(steerable);

                //Debug.Log("FLEE THE FISH: " + targetLightSource.name);
            }
            // Else, if this fish has more light than its target
            else
            {
                // Seek the light source
                seekWhenStronger.Execute(steerable);
            }
        }
        else
        {
            // If the light source has been destroyed, stop performing this action.
            ActionCompleted();
        }

        wallAvoidance.Execute(steerable);
    }
Exemplo n.º 8
0
    public override void Execute(Steerable steerable)
    {
        // Override the steerable's min/max speed
        if (overrideSteerableSpeed)
        {
            steerable.MinSpeed = minSpeed;
            steerable.MaxSpeed = maxSpeed;
        }
        // Override the steerable's max force
        if (overrideMaxForce)
        {
            steerable.MaxForce = maxForce;
        }

        //checks if the boss fish is at the waypoint, if so then no need to move to waypoint anymore
        if ((Vector2)bigFish.GetComponent <Rigidbody>().velocity == Vector2.zero)
        {
            ActionCompleted();
        }
        else
        {
            steerable.AddMoveWaypointForce(waypointList, bigFish, slowingRadius, strengthMultiplier);
        }

        wallAvoidance.Execute(steerable);
    }
Exemplo n.º 9
0
    public override void Execute(Steerable steerable)
    {
        Player player = targetLightSource.gameObject.GetComponent <Player>();

        if (!player.isSafe)
        {
            base.Execute(steerable);

            if (overrideSteerableSpeed)
            {
                steerable.MinSpeed = minSpeed;
                steerable.MaxSpeed = maxSpeed;
            }
            // Override the steerable's max force
            if (overrideMaxForce)
            {
                steerable.MaxForce = maxForce;
            }

            Vector3 position = targetLightSource.transform.position;
            if (overrideBossSpeed(steerable, position))
            {
                steerable.MinSpeed = speedMinIncreased;
                steerable.MaxSpeed = speedMaxIncreased;
            }
            steerable.AddSeekForce(position, strengthMultiplier);
        }
        else
        {
            ActionCompleted();
        }

        wallAvoidance.Execute(steerable);
    }
Exemplo n.º 10
0
    /// <summary>
    /// Makes the steerable seek the current 'targetTransform' instance
    /// </summary>
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetTransform)
        {
            // Override the steerable's min/max speed
            if (overrideSteerableSpeed)
            {
                steerable.MinSpeed = minSpeed;
                steerable.MaxSpeed = maxSpeed;
            }
            // Override the steerable's max force
            if (overrideMaxForce)
            {
                steerable.MaxForce = maxForce;
            }

            // If player's lights are on, seek player
            if (targetTransform.gameObject.CompareTag("Player"))
            {
                Player player = targetTransform.gameObject.GetComponent <Player>();
                if (player.IsDetectable)
                {
                    steerable.AddSeekForce(targetTransform.position, strengthMultiplier);
                    PlaySeekSound();
                }
            }
            else
            {
                steerable.AddSeekForce(targetTransform.position, strengthMultiplier);
            }
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Called every frame when this action needs to be performed.
    /// Applies a fleeing steering force on the given steerable
    /// </summary>
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        // If the action has elapsed its timer
        if (useTimer && timeActive > timer)
        {
            // Inform subscribers that the action is completed. This stops the action's execution.
            ActionCompleted();

            // Reset the timer for the next time the action is performed.
            ResetTimer();
        }

        if (targetTransform)
        {
            // If player's lights are on, seek player
            if (targetTransform.gameObject.CompareTag("Player"))
            {
                Player player = targetTransform.gameObject.GetComponent <Player>();
                if (player.IsDetectable)
                {
                    // Override the steerable's min/max speed
                    if (overrideSteerableSpeed)
                    {
                        steerable.MinSpeed = minSpeed;
                        steerable.MaxSpeed = maxSpeed;
                    }
                    // Override the steerable's max force
                    if (overrideMaxForce)
                    {
                        steerable.MaxForce = maxForce;
                    }
                }
                else
                {
                    // The player is hidden. Thus, the fish should stop fleeing
                    //ActionCompleted();
                }
            }
            else
            {
                // Override the steerable's min/max speed
                if (overrideSteerableSpeed)
                {
                    steerable.MinSpeed = minSpeed;
                    steerable.MaxSpeed = maxSpeed;
                }
                // Override the steerable's max force
                if (overrideMaxForce)
                {
                    steerable.MaxForce = maxForce;
                }
            }

            steerable.AddFleeForce(targetTransform.position, strengthMultiplier);
        }
    }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetSteerable)
        {
            steerable.AddPursueForce(targetSteerable, strengthMultiplier);
        }
    }
Exemplo n.º 13
0
    /// <summary>
    /// Makes the steerable pursue the 'targetTransform' instance
    /// </summary>
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetSteerable)
        {
            steerable.AddPursueForce(targetSteerable, strengthMultiplier);
        }
    }
Exemplo n.º 14
0
    public override void OnAwake()
    {
        // Cache the 'Steerable' component attached to the GameObject performing this action
        steerable = transform.GetComponent <Steerable>();

        // Set the stopping condition's transform to the same Transform that is performing this 'Steer' action.
        // This way, the stopping condition will be tested using this GameObject's position
        stoppingCondition.SetTransform(base.transform);
    }
Exemplo n.º 15
0
    private bool overrideBossSpeed(Steerable steerable, Vector3 target)
    {
        float distance = Vector2.Distance(steerable.transform.position, target);

        if (distance >= distanceSpeedIncrease)
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 16
0
    void Start()
    {
        // Cache the 'Steerable' component attached to the GameObject performing this action
        steerable = transform.GetComponent <Steerable>();

        // Set the stopping condition's transform to the same Transform that is performing this 'Steer' action.
        // This way, the stopping condition will be tested using this GameObject's position
        stoppingCondition.SetTransform(transform);

        // Reset the stopping condition. The stopping condition now knows that the 'Steer' action just started.
        stoppingCondition.Init();
    }
Exemplo n.º 17
0
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetTransform)
        {
            steerable.AddArrivalForce(targetTransform.position, slowingRadius, strengthMultiplier);
        }
        else
        {
            // If the target transform is null, there is nothing to seek. Thus, stop the action
            ActionCompleted();
        }
    }
Exemplo n.º 18
0
    /// <summary>
    /// Initializes the fish object
    /// </summary>
    protected override void Awake()
    {
        // Call parent LightSource Awake() first
        base.Awake();

        // Initialize action priority dictionary
        this.actions = new PriorityDictionary();
        this.Move();

        // Cache the 'Steerable' component attached to the GameObject performing this action
        this.steerable = transform.GetComponent <Steerable>();
        // Set the fish's initial swim direction
        steerable.WanderAngle = defaultWanderAngle;
    }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        if (targetTransform)
        {
            steerable.AddArrivalForce(targetTransform.position, slowingRadius, strengthMultiplier);
        }
        else
        {
            // If the target transform is null, there is nothing to seek. Thus, stop the action
            ActionCompleted();
        }
    }
Exemplo n.º 20
0
    /** Returns a steering force which veers this object towards the given target's future position.
     * This can be seen as a more intelligent version of the 'Seek' behaviour */
    public Vector2 PursueForce(Steerable target)
    {
        // Compute the distance from this GameObject to his target
        float distanceToTarget = (target.Transform.position - Transform.position).magnitude;
        // Calculate the amount of time required for this object to reach his target
        float timeToReachTarget = distanceToTarget / target.MaxSpeed;

        // Determines the target's future position, in 'timeToReachTarget' amount of time
        // This is the position this object will try to pursue to stay ahead of his target
        Vector2 futureTargetPosition = (Vector2)target.Transform.position + target.Rigidbody.velocity * timeToReachTarget;

        // The resulting steering force is the 'Seek' force to the target's future location
        Vector2 pursueForce = SeekForce(futureTargetPosition);

        return(pursueForce);
    }
Exemplo n.º 21
0
        public void SeekToPositionMaxAcceleration()
        {
            Steerable steerer = new Steerable();

            steerer.MaxSpeed     = 10;
            steerer.Acceleration = float.MaxValue;
            steerer.Target       = Vector2.One * 1000;
            steerer.Behaviors.Add(new SeekBehavior());

            float[] targetSpeed = new float[] { 10, 10, 10 };

            for (int i = 0; i < targetSpeed.Length; ++i)
            {
                steerer.Update(ElapsedTime);
                Assert.AreEqual <int>((int)targetSpeed[i], (int)Math.Round(steerer.Speed));
            }
        }
Exemplo n.º 22
0
    /// <summary>
    /// Returns a steering force which makes this object evade the given target.
    /// The target's SteeringManager component is passed to access the target's
    /// max speed easily.
    /// </summary>
    public Vector2 EvadeForce(Steerable targetToEvade)
    {
        // Compute the distance from this GameObject to his target to evade
        float distanceToTarget = (targetToEvade.Transform.position - Transform.position).magnitude;
        // Calculate the amount of time required for this object to reach his target
        float timeToReachTarget = distanceToTarget / targetToEvade.MaxSpeed;

        // Determines the target's future position, in 'timeToReachTarget' amount of time
        // This is the position this object will try to evade to stay away from his target
        Vector2 futureTargetPosition = (Vector2)targetToEvade.Transform.position + targetToEvade.Rigidbody.velocity * timeToReachTarget;

        // Calculate the steering force needed to veer away from the target's future position
        Vector2 evadeForce = FleeForce(futureTargetPosition);

        // Return the steering force used to evade the given target
        return(evadeForce);
    }
Exemplo n.º 23
0
        public void ArriveAtPosition()
        {
            Steerable steerer = new Steerable();

            steerer.MaxSpeed     = 10;
            steerer.Acceleration = 20.02345f;
            steerer.Target       = Vector2.One * 100;
            steerer.Behaviors.Add(new ArriveBehavior());

            float[] targetSpeed = new float[] { 2, 4, 6, 8, 10, 10, 10 };

            for (int i = 0; i < targetSpeed.Length; ++i)
            {
                steerer.Update(ElapsedTime);
                Assert.AreEqual <int>((int)targetSpeed[i], (int)Math.Round(steerer.Speed));
            }

            bool hasStopped      = false;
            bool hasFullyStopped = false;

            for (int i = 0; i < 2000; ++i)
            {
                steerer.Update(ElapsedTime);

                if (hasStopped)
                {
                    Assert.IsTrue(steerer.Speed < steerer.MaxSpeed);
                    if (steerer.Speed <= 0)
                    {
                        hasFullyStopped = true;
                        Assert.IsTrue(Vector2.Distance(Vector2.One * 100, steerer.Position) < 1f);
                    }
                    if (hasFullyStopped)
                    {
                        Assert.IsTrue(steerer.Speed <= float.Epsilon);
                    }
                }
                if ((int)Math.Round(steerer.Speed) != (int)Math.Round(steerer.MaxSpeed))
                {
                    hasStopped = true;
                }
            }
            Assert.IsTrue(hasStopped);
            Assert.IsTrue(hasFullyStopped);
        }
    public override void Execute(Steerable steerable)
    {
        // Override the steerable's min/max speed
        if (overrideSteerableSpeed)
        {
            steerable.MinSpeed = minSpeed;
            steerable.MaxSpeed = maxSpeed;
        }
        // Override the steerable's max force
        if (overrideMaxForce)
        {
            steerable.MaxForce = maxForce;
        }

        cohesion.Execute(steerable);
        alignment.Execute(steerable);
        separation.Execute(steerable);
        wallAvoidance.Execute(steerable);
        wander.Execute(steerable);
    }
Exemplo n.º 25
0
    public override void Execute(Steerable steerable)
    {
        // Override the steerable's min/max speed
        if (overrideSteerableSpeed)
        {
            steerable.MinSpeed = minSpeed;
            steerable.MaxSpeed = maxSpeed;
        }
        // Override the steerable's max force
        if (overrideMaxForce)
        {
            steerable.MaxForce = maxForce;
        }

        cohesion.Execute(steerable);
        alignment.Execute(steerable);
        separation.Execute(steerable);
        wallAvoidance.Execute(steerable);
        wander.Execute(steerable);
    }
Exemplo n.º 26
0
        public void ArriveAtPositionNearby()
        {
            Steerable steerer = new Steerable();

            steerer.MaxSpeed     = 10;
            steerer.Acceleration = 20.02345f;
            steerer.Target       = Vector2.One * 5;
            steerer.Behaviors.Add(new ArriveBehavior());

            bool  hasStopped      = false;
            bool  hasFullyStopped = false;
            float previousSpeed   = float.MinValue;

            for (int i = 0; i < 200; ++i)
            {
                steerer.Update(ElapsedTime);

                if (hasStopped)
                {
                    Assert.IsTrue(steerer.Speed < steerer.MaxSpeed);
                    if (steerer.Speed <= 0)
                    {
                        hasFullyStopped = true;
                        Assert.IsTrue(Vector2.Distance(Vector2.One * 5, steerer.Position) < 0.5f);
                    }
                    if (hasFullyStopped)
                    {
                        Assert.IsTrue(steerer.Speed <= float.Epsilon);
                    }
                }
                if (steerer.Speed < previousSpeed)
                {
                    hasStopped = true;
                }
                previousSpeed = steerer.Speed;
            }
            Assert.IsTrue(hasStopped);
            Assert.IsTrue(hasFullyStopped);
        }
Exemplo n.º 27
0
    protected Vector3 followLeader(Steerable leader, float followingDist)
    {
        /*Produces a steering towards poit just behind a leader
         * * @param leader object to follow as the leader
         * * @param followingDist the distance to which we follow the leader
         * @return following force
         */

        Vector3 tv = -leader.velocity;

        tv = Vector3.Normalize(tv) * followingDist;
        Vector3 behindPos = leader.transform.position + tv;


        Vector3 steering = seek(behindPos, true);

        //steering = steering + separation (1f);

//		steering = Vector3.ClampMagnitude (steering, 0.02f);
//		steering = steering / mass;

        return(steering);
    }
Exemplo n.º 28
0
 /// <summary>
 /// Creates a new instance of Navigator.
 /// </summary>
 public Navigator()
 {
     steerable           = new Steerable();
     steerable.BlendMode = SteeringBehaviorBlendMode.Solo;
     steerable.Behaviors.Add(new StuckAvoidanceBehavior());
     steerable.Behaviors.Add(wallAvoidance = new WallAvoidanceBehavior()
     {
         Enabled = false
     });
     steerable.Behaviors.Add(steerableAvoidance = new SteerableAvoidanceBehavior()
     {
         Enabled = false
     });
     steerable.Behaviors.Add(separation = new SeparationBehavior()
     {
         Enabled = false
     });
     steerable.Behaviors.Add(arrive = new ArriveBehavior()
     {
         Enabled = false
     });
     waypoints = new Queue <Vector3>();
 }
 public Pursue(int priority, string id, Steerable targetSteerable)
     : base(priority, id)
 {
     this.targetSteerable = targetSteerable;
 }
Exemplo n.º 30
0
 public Pursue(int priority, string id, Steerable targetSteerable) : base(priority, id)
 {
     this.targetSteerable = targetSteerable;
 }
Exemplo n.º 31
0
    // void Execute(Steerable steerable, SteeringBehavior steeringBehavior);

    /// <summary>
    /// Called every frame when this action needs to be performed.
    /// Applies the action on the given steerable
    /// </summary>
    public virtual void Execute(Steerable steerable)
    {
        timeActive += Time.deltaTime;
    }
    void Start()
    {
        // Cache the 'Steerable' component attached to the GameObject performing this action
        steerable = transform.GetComponent<Steerable>();

        // Set the stopping condition's transform to the same Transform that is performing this 'Steer' action.
        // This way, the stopping condition will be tested using this GameObject's position
        stoppingCondition.SetTransform(transform);

        // Reset the stopping condition. The stopping condition now knows that the 'Steer' action just started.
        stoppingCondition.Init();
    }
    /// <summary>
    /// Initializes the fish object
    /// </summary>
    protected override void Awake()
    {
        // Call parent LightSource Awake() first
        base.Awake();

        // Initialize action priority dictionary
        this.actions = new PriorityDictionary();
        this.Move();

        // Cache the 'Steerable' component attached to the GameObject performing this action
        this.steerable = transform.GetComponent<Steerable>();
        // Set the fish's initial swim direction
        steerable.WanderAngle = defaultWanderAngle;
    }
Exemplo n.º 34
0
 /// <summary>
 /// Adds a force which evades the given target. Instead of simply moving away from his target, this seekable flees
 /// his target's future position, making him smarter at dodging his target.
 /// </summary>
 /// <param name="multiplier">The amount by which the seek force is multiplied before being added to the steerable's steering force
 public void AddEvadeForce(Steerable targetToEvade, float multiplier)
 {
     steeringForce += EvadeForce(targetToEvade) * multiplier;
 }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddWallAvoidanceForce(avoidanceForce, maxViewDistance, obstacleLayer, strengthMultiplier);
    }
Exemplo n.º 36
0
    /// <summary>
    /// Adds a force which steers the steerable away from its neighbours
    /// </summary>
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddSeparationForce(strengthMultiplier);
    }
 /// <summary>
 /// Pursue the given target. Moves the steerable to his target's future position.
 /// </summary>
 /// <param name="multiplier">The amount by which the seek force is multiplied before being added to the steerable's steering force
 public void AddPursueForce(Steerable target, float multiplier)
 {
     steeringForce += PursueForce (target) * multiplier;
 }
 /// <summary>
 /// Adds a force which evades the given target. Instead of simply moving away from his target, this seekable flees
 /// his target's future position, making him smarter at dodging his target.
 /// </summary>
 /// <param name="multiplier">The amount by which the seek force is multiplied before being added to the steerable's steering force
 public void AddEvadeForce(Steerable targetToEvade, float multiplier)
 {
     steeringForce += EvadeForce (targetToEvade) * multiplier;
 }
Exemplo n.º 39
0
    /// <summary>
    /// Executes the wander action on the given steerable, making it
    /// wander in a random direction
    /// </summary>
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddWanderForce(circleDistance, circleRadius, angleChange, strengthMultiplier);
    }
Exemplo n.º 40
0
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        // If the action has elapsed its timer
        if (useTimer && timeActive > timer)
        {
            //Debug.Log("Flee timer elapsed.");

            // Inform subscribers that the action is completed. This stops the action's execution.
            ActionCompleted();

            // Reset the timer for the next time the action is performed.
            ResetTimer();
        }

        if (targetTransform)
        {
            // If player's lights are on, seek player
            if (targetTransform.gameObject.CompareTag("Player"))
            {
                Player player = targetTransform.gameObject.GetComponent<Player>();
                if (player.IsDetectable())
                {
                    // Override the steerable's min/max speed
                    if (overrideSteerableSpeed)
                    {
                        steerable.MinSpeed = minSpeed;
                        steerable.MaxSpeed = maxSpeed;
                    }
                    // Override the steerable's max force
                    if (overrideMaxForce)
                    {
                        steerable.MaxForce = maxForce;
                    }

                    //Debug.Log("FLEE THE PLAYER [Flee.Execute()]");
                }
                else
                {
                    // The player is hidden. Thus, the fish should stop fleeing
                    //ActionCompleted();
                }
            }
            else
            {
                // Override the steerable's min/max speed
                if (overrideSteerableSpeed)
                {
                    steerable.MinSpeed = minSpeed;
                    steerable.MaxSpeed = maxSpeed;
                }
                // Override the steerable's max force
                if (overrideMaxForce)
                {
                    steerable.MaxForce = maxForce;
                }
            }

            steerable.AddFleeForce(targetTransform.position, strengthMultiplier);
        }
    }
    /// <summary>
    /// Returns a steering force which makes this object evade the given target.
    /// The target's SteeringManager component is passed to access the target's
    /// max speed easily.
    /// </summary>
    private Vector2 EvadeForce(Steerable targetToEvade)
    {
        // Compute the distance from this GameObject to his target to evade
        float distanceToTarget = (targetToEvade.Transform.position - Transform.position).magnitude;
        // Calculate the amount of time required for this object to reach his target
        float timeToReachTarget = distanceToTarget / targetToEvade.MaxSpeed;

        // Determines the target's future position, in 'timeToReachTarget' amount of time
        // This is the position this object will try to evade to stay away from his target
        Vector2 futureTargetPosition = (Vector2)targetToEvade.Transform.position + (Vector2)targetToEvade.Rigidbody.velocity * timeToReachTarget;

        // Calculate the steering force needed to veer away from the target's future position
        Vector2 evadeForce = FleeForce(futureTargetPosition);

        // Return the steering force used to evade the given target
        return evadeForce;
    }
Exemplo n.º 42
0
 /// <summary>
 /// Pursue the given target. Moves the steerable to his target's future position.
 /// </summary>
 /// <param name="multiplier">The amount by which the seek force is multiplied before being added to the steerable's steering force
 public void AddPursueForce(Steerable target, float multiplier)
 {
     steeringForce += PursueForce(target) * multiplier;
 }
    // Need to be able to set these floats elsewhere;
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddWanderForce(circleDistance, circleRadius, angleChange, strengthMultiplier);
    }
    /** Returns a steering force which veers this object towards the given target's future position.
      * This can be seen as a more intelligent version of the 'Seek' behaviour */
    private Vector2 PursueForce(Steerable target)
    {
        // Compute the distance from this GameObject to his target
        float distanceToTarget = (target.Transform.position - Transform.position).magnitude;
        // Calculate the amount of time required for this object to reach his target
        float timeToReachTarget = distanceToTarget / target.MaxSpeed;

        // Determines the target's future position, in 'timeToReachTarget' amount of time
        // This is the position this object will try to pursue to stay ahead of his target
        Vector2 futureTargetPosition = (Vector2)target.Transform.position + (Vector2)target.Rigidbody.velocity * timeToReachTarget;

        // The resulting steering force is the 'Seek' force to the target's future location
        Vector2 pursueForce = SeekForce(futureTargetPosition);

        return pursueForce;
    }
Exemplo n.º 45
0
    /// <summary>
    /// Called every frame when the action needs to be performed.
    /// Applies a steering force on the given steerable
    /// </summary>
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddAlignmentForce(strengthMultiplier);
    }
	protected Vector3 followLeader(Steerable leader, float followingDist){
		/*Produces a steering towards poit just behind a leader
		 * * @param leader object to follow as the leader
		 * * @param followingDist the distance to which we follow the leader 
		 * @return following force
		 */

		Vector3 tv = -leader.velocity;
		tv = Vector3.Normalize (tv) * followingDist;
		Vector3 behindPos = leader.transform.position + tv;
		
		
		Vector3 steering = seek (behindPos, true);
		//steering = steering + separation (1f);

//		steering = Vector3.ClampMagnitude (steering, 0.02f);
//		steering = steering / mass;
		
		return steering;
	}
 private bool overrideBossSpeed(Steerable steerable, Vector3 target)
 {
     float distance = Vector2.Distance(steerable.transform.position, target);
     if (distance >= distanceSpeedIncrease)
     {
         return true;
     }
     return false;
 }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddAlignmentForce(strengthMultiplier);
    }
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddSeparationForce(strengthMultiplier);
    }
Exemplo n.º 50
0
    public override void Execute(Steerable steerable)
    {
        base.Execute(steerable);

        steerable.AddWallAvoidanceForce(avoidanceForce, maxViewDistance, obstacleLayer, strengthMultiplier);
    }