Example #1
0
    void ComputeForces()
    {
        // SET force to zero
        force = Vector3.zero;

        // FOR i = 0 to behaviours count
        for (int i = 0; i < behaviours.Length; i++)
        {
            SteeringBehaviour behaviour = behaviours[i];
            // IF behaviour is not enabled
            if (!behaviour.enabled)
            {
                // CONTINUE
                continue;
            }
            // SET force to force + behaviour's force
            force += behaviour.GetForce();
            // IF force is greater than maxVelocity
            if (force.magnitude > maxVelocity)
            {
                // SET force to force normalized x maxVelocity
                force = force.normalized * maxVelocity;
                // BREAK
                break;
            }
        }
    }
Example #2
0
    void ComputeForces()
    {
        // SET force to zero
        force = Vector3.zero;

        // FOR i := 0 to behaviours count
        for (int i = 0; i < behaviours.Count; i++)
        {
            // IF behavior is enabled
            SteeringBehaviour behaviour = behaviours[i];
            if (!behaviour.enabled)
            {
                continue;
            }

            // SET force to force + behaviour force
            force += behaviour.GetForce() * behaviour.weighting;

            // IF force is greater than maxVelocity
            if (force.magnitude > maxVelocity)
            {
                // SET force to force normalized x maxVelocity
                force = force.normalized * maxVelocity;
                // BREAK
                break;
            }
        }
    }
Example #3
0
    // Calculates all forces from attached SteeringBehaviours
    void ComputeForces()
    {
        // Reset force before calculation
        force = Vector3.zero;

        // Loop through all behaviours
        for (int i = 0; i < behaviours.Count; i++)
        {
            // Get current behaviour
            SteeringBehaviour b = behaviours[i];

            // Check if behaviour is active and enabled
            if (!b.isActiveAndEnabled)
            {
                // Skip over to next behaviour
                continue;
            }

            // Apply behaviour's force to our final force
            force += b.GetForce() * b.weighting;

            // Check if force has gone over maxSpeed
            if (force.magnitude > maxSpeed)
            {
                // Cap the force down to maxSpeed
                force = force.normalized * maxSpeed;

                // Exit for loop
                break;
            }
        }
    }
Example #4
0
 void ComputeForces()
 {
     // SET force to zero
     force = Vector3.zero; // When you create a variable in a function,
                           // It only exists within that function.
                           // FOR i = 0 to behaviours length
     for (int i = 0; i < behaviours.Length; i++)
     {
         SteeringBehaviour behaviour = behaviours[i];
         // IF behaviour is not enabled
         if (!behaviour.enabled)
         {
             // CONTINUE
             continue;
         }
         // SET force to force + behaviour's force
         force += behaviour.GetForce();
         // IF force is greater than maxVelocity
         if (force.magnitude > maxVelocity)
         {
             // SET force to force normalized x maxVelocity
             force = force.normalized * maxVelocity;
             // BREAK
             break;
         }
     }
 }
Example #5
0
    void ComputeForces()
    {
        // reset the force
        force = Vector3.zero;

        //Loop through all behaviours attached to gameobject
        for (int i = 0; i < behaviours.Count; i++)
        {
            SteeringBehaviour behaviour = behaviours[i];
            if (!behaviour.isActive)
            {
                continue;
            }


            // Calculate the force from it
            force += behaviour.GetForce() * behaviour.weighting;

            //If the force are too big
            if (force.magnitude > maxVelocity)
            {
                //Clamp it to the nax
                force = force.normalized * maxVelocity;
                //stop calculating
                break;
            }
        }
    }
Example #6
0
 void ComputeForces()
 {
     force = Vector3.zero;
     for (int i = 0; i < behaviours.Count; i++)
     {
         SteeringBehaviour b = behaviours[i];
         if (!b.isActiveAndEnabled)
         {
             continue;
         }
         force += b.GetForce() * b.weighting;
         if (force.magnitude > maxSpeed)
         {
             force = force.normalized * maxSpeed;
             break;
         }
     }
 }