public override Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> food, List <GameObject> Menace, Vector3 NextWaypoint) { Vector3 desired_velocity = Vector3.zero; Vector3 nearestFoodPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); if (food.Count <= 0) { return(Vector3.zero); } for (int i = 0; i < food.Count; i++) { float distActualNearest = Vector3.Distance(nearestFoodPosition, actualBoid.transform.position); float otherDist = Vector3.Distance(food.ToArray()[i].transform.position, actualBoid.transform.position); if (otherDist < distActualNearest) { nearestFoodPosition = food.ToArray()[i].transform.position; } } Vector3 diff = nearestFoodPosition - actualBoid.transform.position; desired_velocity = diff.normalized * maxSpeed; return(desired_velocity - actualBoid.velocity); }
public override Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> food, List <GameObject> Menace, Vector3 NextWaypoint) { Vector3 desired_velocity = Vector3.zero; int nearUnitsCount = 0; foreach (BOIDUnit b in nearUnits) { if (actualBoid == b) { continue; } Vector3 diff = actualBoid.transform.position - b.transform.position; float dist = diff.magnitude; if (dist < radius) { nearUnitsCount++; desired_velocity += b.velocity; } } if (nearUnitsCount > 0) { desired_velocity /= nearUnitsCount; return(desired_velocity - actualBoid.velocity); } else { return(Vector3.zero); } }
public override Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> food, List <GameObject> Menace, Vector3 NextWaypoint) { Vector3 desired_velocity = Vector3.zero; Vector3 diff = NextWaypoint - actualBoid.transform.position; desired_velocity = diff.normalized * maxSpeed; return(desired_velocity - actualBoid.velocity); }
public override Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> food, List <GameObject> Menace, Vector3 NextWaypoint) { Vector3 desired_velocity = Vector3.zero; for (int i = 0; i < Menace.Count; i++) { Vector3 diff = actualBoid.transform.position - Menace[i].transform.position; float dist = Vector3.Distance(actualBoid.transform.position, Menace[i].transform.position); if (dist < radius) { Vector3 desiredPosition = Menace[i].transform.position - actualBoid.transform.position; desired_velocity = (desiredPosition.normalized * maxSpeed) - actualBoid.velocity; return(desired_velocity * -1.0f); } } return(Vector3.zero); }
public override Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> food, List <GameObject> Menace, Vector3 NextWaypoint) { Vector3 desired_velocity = Vector3.zero; float nearUnitsCount = 0; if (nearUnits.Count > 0) { foreach (BOIDUnit b in nearUnits) { if (b == actualBoid) { continue; } Vector3 diff = actualBoid.transform.position - b.transform.position; float dist = /*diff.magnitude*/ Vector3.Distance(actualBoid.transform.position, b.transform.position); if (dist < radius) { nearUnitsCount++; if (dist > 0) { desired_velocity += diff.normalized / /*Mathf.Pow(dist, 2)*/ dist; } } } } if (nearUnitsCount > 0) { return(desired_velocity * maxSpeed); } else { return(new Vector3(0, 0, 0)); } }
public override Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> food, List <GameObject> Menace, Vector3 NextWaypoint) { Vector3 desired_velocity = Vector3.zero; float nearUnitsCount = 0; if (nearUnits.Count > 0) { foreach (BOIDUnit b in nearUnits) { if (b == actualBoid) { continue; } var diff = actualBoid.transform.position - b.transform.position; float dist = diff.magnitude; if (dist < radius) { nearUnitsCount++; desired_velocity += b.transform.position; } } } if (nearUnitsCount > 0) { desired_velocity /= nearUnitsCount; //desired_velocity -= actualBoid.transform.position; //desired_velocity = desired_velocity.normalized * maxSpeed; return(desired_velocity /*- actualBoid.velocity*/); } else { return(new Vector3(0, 0, 0)); } }
public abstract Vector3 GetForce(List <BOIDUnit> nearUnits, BOIDUnit actualBoid, float maxSpeed, List <GameObject> foodList, List <GameObject> menaceList, Vector3 NextWaypoint);