コード例 #1
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 maxSpeedforce = force.normalized * maxSpeed
             force = force.normalized * maxSpeed;
             // Exit for Loop
             break;
         }
     }
 }
コード例 #2
0
 void ComputeForces()
 {
     // SET force = Vector3.zero
     force = Vector3.zero;
     // FOR i := 0 < behaviours.Count
     for (int i = 0; i < behaviours.Count; i++)
     {
         // LET behaviour = behaviours[i]
         SteeringBehaviour behaviour = behaviours[i];
         // IF behaviour.isActiveAndEnabled == false
         if (!behaviour.isActiveAndEnabled)
         {
             // CONTINUE
             continue;
         }
         // SET force = force + behaviour.GetForce() * behaviour.weighting
         force += behaviour.GetForce() * behaviour.weighting;
         // IF force.magnitude > maxSpeed
         if (force.magnitude > maxSpeed)
         {
             // SET force = force.normalized * maxSpeed
             force = force.normalized * maxSpeed;
             // BREAK
             break;
         }
     }
 }
コード例 #3
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;
         }
     }
 }
コード例 #4
0
 // Calculates all forces from attached SteeringBehaviours
 void ComputeForces()
 {
     force = Vector3.zero;
     for (int i = 0; i < behaviours.Count; i++)
     {
         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)
         {
             // Set force = force.normalized * maxSpeed
             force = force.normalized * maxSpeed;
             // Exit for loop
             break;
         }
     }
 }