public static SteeringOutput GetSteering(KinematicState ownKS, GameObject repulsor, float scareRadius = 40f, float fleeWeight = 0.2f, string idTag = "BOID", float cohesionThreshold = 40f, float repulsionThreshold = 10f, float wanderRate = 10f) { SteeringOutput fleeOutput; if ((ownKS.position - repulsor.transform.position).magnitude <= scareRadius) { fleeOutput = Flee.GetSteering(ownKS, repulsor); } else { fleeOutput = NULL_STEERING; } SteeringOutput result = Flocking.GetSteering(ownKS, idTag, cohesionThreshold, repulsionThreshold, wanderRate); // beware, Flocking may return NULL_STEERING. In that case, just apply flee if (result == NULL_STEERING) { return(fleeOutput); } result.linearAcceleration = result.linearAcceleration * (1 - fleeWeight) + fleeOutput.linearAcceleration * fleeWeight; result.angularAcceleration = result.angularAcceleration * (1 - fleeWeight) + fleeOutput.angularAcceleration * fleeWeight; return(result); }
protected override SteeringOutput GetSteering() { SteeringOutput result = Flee.GetSteering(m_ownKS, m_info.m_target); base.ApplyFacingPolicy(m_info.m_facingPolicy, result); return(result); }
public override SteeringOutput GetSteering() { // no KS? get it if (this.ownKS == null) { this.ownKS = GetComponent <KinematicState>(); } return(Flee.GetSteering(this.ownKS, this.target)); }
public override SteeringOutput GetSteering() { // no KS? get it if (this.ownKS == null) { this.ownKS = GetComponent <KinematicState>(); } SteeringOutput result = Flee.GetSteering(this.ownKS, this.target); base.applyRotationalPolicy(rotationalPolicy, result, this.target); return(result); }
public static SteeringOutput GetSteering(KinematicState ownKS, GameObject target, float maxPredictionTime = 3f) { // we need to know the kinematic state of the target since we need to know its linear velocity // if target has no kinematic state "give up" and just seek KinematicState targetKS = target.GetComponent <KinematicState> (); if (targetKS == null) { Debug.Log("Evade invoked with a target that has no kinematic state attached. Resorting to Flee"); return(Flee.GetSteering(ownKS, target)); } Vector3 directionToMe = ownKS.position - targetKS.position; float distanceToMe = directionToMe.magnitude; float currentSpeed = targetKS.linearVelocity.magnitude; // determine the time it will take the target to reach me float predictedTimeToMe = distanceToMe / currentSpeed; if (predictedTimeToMe > maxPredictionTime) { predictedTimeToMe = maxPredictionTime; } // now determine future (at predicted time) location of target Vector3 futurePositionOfTarget = targetKS.position + targetKS.linearVelocity * predictedTimeToMe; // is the target going to get me? Does it seem to be moving towards me? if ((futurePositionOfTarget - ownKS.position).magnitude < 1) { // impossible to flee your own position. Go somewhere else futurePositionOfTarget = Utils.OrientationToVector(Utils.VectorToOrientation(futurePositionOfTarget) + 1); //return Flee.GetSteering(ownKS, target); } // create surrogate target and place it at future location if (Evade.surrogateTarget == null) { Evade.surrogateTarget = new GameObject("Surrogate Target for evade"); } Evade.surrogateTarget.transform.position = futurePositionOfTarget; // delegate to flee return(Flee.GetSteering(ownKS, surrogateTarget)); }
public static SteeringOutput GetSteering(KinematicState ownKS, GameObject target, bool showWhishker = true, float lookAheadLength = 10f, float avoidDistance = 10f, float secondaryWhiskerAngle = 30f, float secondaryWhiskerRatio = 0.7f) { // give priority to obstacle avoidance SteeringOutput so = ObstacleAvoidance.GetSteering(ownKS, showWhishker, lookAheadLength, avoidDistance, secondaryWhiskerAngle, secondaryWhiskerRatio); if (so == NULL_STEERING) { return(Flee.GetSteering(ownKS, target)); } return(so); }
public static SteeringOutput GetSteering(KinematicState ownKS, SEvade info) { if (info.m_targetLinearVelocity == null) { return(NULL_STEERING); } float l_distanceToMe = (ownKS.m_position - info.m_target.position).magnitude; float l_predictedCollisionTime = l_distanceToMe / info.m_targetLinearVelocity.magnitude; l_predictedCollisionTime = MathExtent.Clip(l_predictedCollisionTime, info.m_maxPredictionTime); SURROGATE_TARGET.position = info.m_target.position + info.m_targetLinearVelocity * l_predictedCollisionTime; return(Flee.GetSteering(ownKS, SURROGATE_TARGET)); }
public static SteeringOutput GetSteering(KinematicState ownKS, GameObject attractor, float seekWeight, string idTag, float cohesionThreshold, float repulsionThreshold, float wanderRate, float vmWeight, float rpWeight, float coWeight, float wdWeight, float distance, float angle, ref bool previous, GameObject self, float tooClose, float safe) { if (previous) { if (SensingUtils.DistanceToTarget(self, attractor) >= safe) { previous = false; //Vector3 pepe = Utils.OrientationToVector(attractor.GetComponent<KinematicState>().orientation + angle).normalized * distance; //SURROGATE_TARGET.transform.position = attractor.transform.position + pepe; return(FlockingAround.GetSteering(ownKS, attractor, seekWeight, idTag, cohesionThreshold, repulsionThreshold, wanderRate, vmWeight, rpWeight, coWeight, wdWeight)); } else { return(Flee.GetSteering(ownKS, attractor)); } } else { if (SensingUtils.DistanceToTarget(self, attractor) < tooClose) { previous = true; return(Flee.GetSteering(ownKS, attractor)); } else { //Vector3 pepe = Utils.OrientationToVector(attractor.GetComponent<KinematicState>().orientation + angle).normalized * distance; //SURROGATE_TARGET.transform.position = attractor.transform.position + pepe; return(FlockingAround.GetSteering(ownKS, attractor, seekWeight, idTag, cohesionThreshold, repulsionThreshold, wanderRate, vmWeight, rpWeight, coWeight, wdWeight)); } } }