//calculate and apply steering forces private void CalcSteeringForce() { Vector3 force = Vector3.zero; //obstacles for (int i = 0; i < obstacles.Length; i++) { force += attr.avoidWt * steer.AvoidObstacle(obstacles[i], attr.avoidDist); } //guys for (int i = 0; i < myGuys.Length; i++) { force += attr.avoidWt * steer.Separate(myGuys[i], attr.avoidDist); //target for (int j = 0; j < targets.Length; j++) { force += steer.Align(targets[j], myGuys[i], attr.avoidDist); force += steer.Cohere(targets[j], myGuys[i], attr.avoidDist); } } Debug.DrawRay(transform.position, force, Color.cyan); //in bounds force += attr.inBoundsWt * steer.StayInBounds(48, Vector3.zero); //seek target force += attr.seekWt * steer.Seek(target.transform.position); force = Vector3.ClampMagnitude(force, attr.maxForce); ApplyForce(force); }
//calculate and apply steering forces private void CalcSteeringForce() { Vector3 force = Vector3.zero; //obstacles for (int i = 0; i < obstacles.Length; i++) { force += steeringAtt.avoidWt * steer.AvoidObstacle(obstacles[i], steeringAtt.avoidDist); } Debug.DrawRay(transform.position, force, Color.cyan); //in bounds //first parameter in stayInBounds determines distance fish can swim from original spawn point------------------------------------------------------------ force += steeringAtt.inBoundsWt * steer.StayInBounds(90, new Vector3(0, 0, 0)); if (force.sqrMagnitude < 5000) { //ugly kludge to adjust behavior for 3 kinds of fish float alWt = (float)steeringAtt.alignmentWt; float coWt = (float)steeringAtt.cohesionWt; float centerWt = (float)steeringAtt.centerWt; if (fishColor == "red") { alWt *= 1.5f; coWt *= 0.8f; } else if (fishColor == "blue") { alWt *= 2f; coWt *= 1.2f; } force += steeringAtt.separationWt * steer.Separate(gm.FlockList); force += alWt * steer.Align(gm.FlockDirections[fishColor]); force += coWt * steer.Cohere(gm.Centroids[fishColor]); force += centerWt * steer.Seek(Vector3.zero); } force = Vector3.ClampMagnitude(force, steeringAtt.maxForce); //force.y = 0; ApplyForce(force); }