// Update is called once per frame public override void Update() { Seperation seperation = new Seperation(); seperation.targets = obstacles; seperation.ai = this; SteeringOutput myMovement = seperation.GetSteering(); LookWhereGoing look = new LookWhereGoing(); look.ai = this; look.target = target; SteeringOutput mySteering = look.GetSteering(); if (mySteering != null) { //linearVelocity += steering.linear * Time.deltaTime; angularVelocity += mySteering.angular * Time.deltaTime; } linearVelocity += myMovement.linear * Time.deltaTime; transform.position += linearVelocity * Time.deltaTime; if (float.IsNaN(angularVelocity)) { angularVelocity = 0; } transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0); }
private void Start() { kinematic = GetComponent <Kinematic>(); switch (moveType) { case SteeringType.Pursue: pursueAI = new Pursue(); pursueAI.character = kinematic; pursueAI.target = target; break; case SteeringType.Evade: evadeAI = new Evade(); evadeAI.character = kinematic; evadeAI.target = target; break; case SteeringType.FollowPath: followAI = new PathFollow(); followAI.character = kinematic; followAI.path = pathOfObjects; break; case SteeringType.Seek: seekAI = new Seek(); seekAI.character = kinematic; seekAI.target = target; break; case SteeringType.Flee: fleeAI = new Flee(); fleeAI.character = kinematic; fleeAI.target = target; break; case SteeringType.Seperation: seperationAI = new Seperation(); seperationAI.character = kinematic; seperationAI.targets = seperateObstacles; break; case SteeringType.Arrive: arriveAI = new Arrive(); arriveAI.character = kinematic; arriveAI.target = target; break; } switch (lookType) { case LookType.Align: alignAI = new Align(); alignAI.character = kinematic; alignAI.target = target; break; } }
// Start is called before the first frame update void Start() { agentScript = gameObject.AddComponent <Agent>(); agentScript.maxSpeed = maxSpeed; cohesionScript = gameObject.AddComponent <Cohesion>(); seperationScript = gameObject.AddComponent <Seperation>(); cohesionScript.targets = target.GetComponent <SquadLeader>().children; seperationScript.targets = cohesionScript.targets; ChangeState(UnitStates.Seek); }
private void Awake() { steering = new BlendedSteering(); //Create behaviors to go into the bird Arrive arriveAI = new Arrive(); arriveAI.character = GetComponent <Kinematic>(); arriveAI.target = arriveTarget; Seperation seperateAI = new Seperation(); seperateAI.character = GetComponent <Kinematic>(); GameObject[] allBirds = GameObject.FindGameObjectsWithTag("bird"); Kinematic[] allOtherBirdKinematics = new Kinematic[allBirds.Length]; int j = 0; foreach (GameObject bird in allBirds) { if (bird != this) { allOtherBirdKinematics[j] = bird.GetComponent <Kinematic>(); j++; } else { Debug.Log("caught myself"); } } seperateAI.targets = allOtherBirdKinematics; LookWhereGoing lookAI = new LookWhereGoing(); lookAI.character = GetComponent <Kinematic>(); //Set up the blended steering array //We need three for Seperation, Arrive, and LookWhereGoing steering.behaviors = new BehaviorAndWeight[3]; steering.behaviors[0] = new BehaviorAndWeight(); steering.behaviors[1] = new BehaviorAndWeight(); steering.behaviors[2] = new BehaviorAndWeight(); //Assign the specific behaviors steering.behaviors[0].behavior = arriveAI; steering.behaviors[1].behavior = seperateAI; steering.behaviors[2].behavior = lookAI; //Now set the weight of each behavior steering.behaviors[0].weight = 1f; steering.behaviors[1].weight = 20f; steering.behaviors[2].weight = 4f; }
// Start is called before the first frame update protected virtual void Start() { arrive = new Arrive(); look = new LookWhereGoing(); seperate = new Seperation(); avoid = new ObstacleAvoidance(); flockGroups = new BlendedSteering[3]; arrive.target = target; arrive.ai = this; look.target = target; look.ai = this; seperate.ai = this; avoid.ai = this; AbstractKinematic[] kBirds; GameObject[] birds = GameObject.FindGameObjectsWithTag("Bird"); kBirds = new AbstractKinematic[birds.Length - 1]; int j = 0; for (int i = 0; i < birds.Length - 1; i++) { if (birds[i] == this) { continue; } kBirds[j++] = birds[i].GetComponent <AbstractKinematic>(); } seperate.targets = kBirds; InitializePriorityOne(); InitializePriorityTwo(); InitializePriorityThree(); /* * flocking.behaviors = new BehaviorAndWeight[3]; * BehaviorAndWeight behavior1 = new BehaviorAndWeight(); * behavior1.behavior = arrive; * behavior1.weight = 100f; * flocking.behaviors[0] = behavior1; * BehaviorAndWeight behavior2 = new BehaviorAndWeight(); * behavior2.behavior = look; * behavior2.weight = 1f; * flocking.behaviors[1] = behavior2; * BehaviorAndWeight behavior3 = new BehaviorAndWeight(); * behavior3.behavior = seperate; * behavior3.weight = 20f; * flocking.behaviors[2] = behavior3; */ }
private void Update() { var tracks = TrackRepository.GetAll().ToList(); var seperationAlerts = SeperationAlertRepository.GetAll(); var list = seperationAlerts.Select(alerts => tracks.FirstOrDefault(o => o.Tag == alerts.Tag1)).ToList(); var toRemove = Seperation.CheckSeperation(list).ToList(); if (!toRemove.Any()) return; foreach (var track in toRemove) { SeperationAlertRepository.Remove(track.Item1, track.Item2); } }
public void ReceiverOnTransponderDataReady(object sender, RawTransponderDataEventArgs rawTransponderDataEventArgs) { Update(); foreach (var v in rawTransponderDataEventArgs.TransponderData) { TrackRepository.Add(v); } foreach (var t in TrackRepository.GetAll()) { t.IsInAirspace = AirSpace.CheckAirSpace(t.Vector); Seperation.CheckSeperation(TrackRepository.FlightTracks.ToList(), t); } if (ConsoleOut) { Display(); } }
public void seperationConditionTest(string tag, int x, int y, int altitude, string timestamp, string tag2, int x2, int y2, int altitude2, string timestamp2, int expected) { string format = "yyyyMMddHHmmssfff"; DateTime plane1Time = DateTime.ParseExact(timestamp, format, CultureInfo.InvariantCulture); DateTime plane2Time = DateTime.ParseExact(timestamp2, format, CultureInfo.InvariantCulture); var airplane1 = new Airplane(tag, x, y, altitude, plane1Time); var airplane2 = new Airplane(tag2, x2, y2, altitude2, plane2Time); List <Airplane> airplaneList = new List <Airplane>(); airplaneList.Add(airplane1); airplaneList.Add(airplane2); Seperation septest = new Seperation(); var strlist = septest.ConditionDetected(airplaneList); var actual = strlist.Count; Assert.AreEqual(expected, actual); }
// Update is called once per frame void Update() { //Debug.Log(target); // Check distance to see if steering behavior should be applied to AI // float targetDist = (transform.position - target.transform.position).magnitude; // if (!DistanceActivation || targetDist >= activationRange) { } transform.position += linearVelocity * Time.deltaTime; // adding angular velocity to current transform rotation y component if (float.IsNaN(angularVelocity)) { angularVelocity = 0; } transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0); // control to switch to proper steering behavior if (avoidObstacles) { ObstacleAvoidance avoid = new ObstacleAvoidance(); avoid.ai = this; SteeringOutput avoidForce = avoid.GetSteering(); if (avoidForce != null) { linearVelocity += avoidForce.linear; } } if (seperationObstacles.Length > 0) { Seperation seperation = new Seperation(); seperation.targets = seperationObstacles; seperation.ai = this; SteeringOutput seperateForce = seperation.GetSteering(); // check to see if steering is greater than zero and lock out control from other steering if (seperateForce.linear.magnitude > 0) { seperating = true; } else { seperating = false; } linearVelocity += seperateForce.linear * Time.deltaTime; } if (collisionAvoidance.Length > 0) { CollisionAvoidance avoidKinematic = new CollisionAvoidance(); avoidKinematic.ai = this; avoidKinematic.targets = collisionAvoidance; SteeringOutput avoidKinematicForce = avoidKinematic.GetSteering(); if (avoidKinematicForce != null) { linearVelocity += avoidKinematicForce.linear; } } switch (movementType) { case "seek": Seek mySeek = new Seek(); mySeek.ai = this; // if seek is false set seek property on class to false to activate flee mySeek.seek = true; mySeek.target = target; SteeringOutput steeringSeek = mySeek.GetSteering(); if (!seperating) { linearVelocity += steeringSeek.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; case "flee": Seek myFlee = new Seek(); myFlee.ai = this; // if seek is false set seek property on class to false to activate flee myFlee.seek = false; myFlee.target = target; SteeringOutput steeringFlee = myFlee.GetSteering(); if (!seperating) { linearVelocity += steeringFlee.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; case "arrive": Arrive myArrive = new Arrive(); myArrive.ai = this; myArrive.target = target; SteeringOutput steeringArrive = myArrive.GetSteering(); if (!seperating) { linearVelocity += steeringArrive.linear * Time.deltaTime; } break; case "pursue": Pursue myPursue = new Pursue(); myPursue.ai = this; myPursue.target = target; SteeringOutput steeringPursue = myPursue.GetSteering(); if (!seperating) { linearVelocity += steeringPursue.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; case "evade": Pursue myEvade = new Pursue(); myEvade.ai = this; myEvade.target = target; // This changes the seek flag in the parent Seek class of Pursue, sending it the flee vector instead myEvade.seek = false; SteeringOutput steeringEvade = myEvade.GetSteering(); if (!seperating) { linearVelocity += steeringEvade.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; default: // provide no input break; // If obstacles have been provided, return steering to seperate from them } switch (rotationType) { case "face": Face myFace = new Face(); myFace.ai = this; myFace.target = target; SteeringOutput steeringFace = myFace.GetSteering(); if (steeringFace != null) { // linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steeringFace.angular * Time.deltaTime; } break; case "align": Align myAlign = new Align(); myAlign.ai = this; myAlign.target = target; SteeringOutput steeringAlign = myAlign.GetSteering(); if (steeringAlign != null) { //linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steeringAlign.angular * Time.deltaTime; } break; case "look": LookWhereGoing myLook = new LookWhereGoing(); myLook.ai = this; myLook.target = target; SteeringOutput steeringLook = myLook.GetSteering(); if (steeringLook != null) { //linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steeringLook.angular * Time.deltaTime; } break; default: //provide no input break; } }
void Start() { steering = new PrioritySteering(); //Make 2 groups, one for flocking, and one for avoiding obstacles steering.groups = new BlendedSteering[2]; //Initialize them steering.groups[0] = new BlendedSteering(); steering.groups[1] = new BlendedSteering(); //Put obstacle avoidance into its own group ObstacleAvoidance avoidAI = new ObstacleAvoidance(); avoidAI.character = GetComponent <Kinematic>(); //Initialize array, only 1 behavior needed in this group's consideration steering.groups[0].behaviors = new BehaviorAndWeight[1]; steering.groups[0].behaviors[0] = new BehaviorAndWeight(); //Assign specific behavior steering.groups[0].behaviors[0].behavior = avoidAI; //Set weight steering.groups[0].behaviors[0].weight = 4f; //Create behaviors to go into the bird Arrive arriveAI = new Arrive(); arriveAI.character = GetComponent <Kinematic>(); arriveAI.target = arriveTarget; Seperation seperateAI = new Seperation(); seperateAI.character = GetComponent <Kinematic>(); GameObject[] allBirds = GameObject.FindGameObjectsWithTag("bird"); Kinematic[] allOtherBirdKinematics = new Kinematic[allBirds.Length]; int j = 0; foreach (GameObject bird in allBirds) { if (bird != this) { allOtherBirdKinematics[j] = bird.GetComponent <Kinematic>(); j++; } else { Debug.Log("caught myself"); } } seperateAI.targets = allOtherBirdKinematics; LookWhereGoing lookAI = new LookWhereGoing(); lookAI.character = GetComponent <Kinematic>(); //Set up flocking group in priority steering steering.groups[1].behaviors = new BehaviorAndWeight[3]; steering.groups[1].behaviors[0] = new BehaviorAndWeight(); steering.groups[1].behaviors[1] = new BehaviorAndWeight(); steering.groups[1].behaviors[2] = new BehaviorAndWeight(); //Assign specific behaviors steering.groups[1].behaviors[0].behavior = arriveAI; steering.groups[1].behaviors[1].behavior = seperateAI; steering.groups[1].behaviors[2].behavior = lookAI; //Set weight of each behavior steering.groups[1].behaviors[0].weight = 1f; steering.groups[1].behaviors[1].weight = 20f; steering.groups[1].behaviors[2].weight = 4f; }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case steeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = target; SteeringOutput seeking = seek.getSteering(); if (seeking != null) { linearVelocity += seeking.linearVelocity * Time.deltaTime; angularVelocity += seeking.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Flee: Flee flee = new Flee(); flee.character = this; flee.target = target; SteeringOutput fleeing = flee.getSteering(); if (fleeing != null) { linearVelocity += fleeing.linearVelocity * Time.deltaTime; angularVelocity += fleeing.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Align: Align align = new Align(); align.character = this; align.target = target; SteeringOutput aligning = align.getSteering(); if (aligning != null) { linearVelocity += aligning.linearVelocity * Time.deltaTime; angularVelocity += aligning.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Face: Face face = new Face(); face.character = this; face.target = target; SteeringOutput facing = face.getSteering(); if (facing != null) { linearVelocity += facing.linearVelocity * Time.deltaTime; angularVelocity += facing.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.LookWhereGoing: LookWhereGoing look = new LookWhereGoing(); look.character = this; look.target = target; SteeringOutput looking = look.getSteering(); if (looking != null) { linearVelocity += looking.linearVelocity * Time.deltaTime; angularVelocity += looking.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = target; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linearVelocity += arriving.linearVelocity * Time.deltaTime; angularVelocity += arriving.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.SeekLWYG: LookWhereGoing lwyg = new LookWhereGoing(); Seek seek1 = new Seek(); seek1.character = this; seek1.target = target; lwyg.character = this; lwyg.target = target; SteeringOutput seeker = seek1.getSteering(); SteeringOutput lwyger = lwyg.getSteering(); if (seeker != null && lwyger != null) { linearVelocity += seeker.linearVelocity * Time.deltaTime; angularVelocity += lwyger.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.PathFollow: follow.character = this; face1.character = this; follow.path = pathArray; face1.target = target; SteeringOutput following = follow.getSteering(); SteeringOutput facer1 = face1.getSteering(); if (following != null) { linearVelocity += following.linearVelocity * Time.deltaTime; //angularVelocity += facer1.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Pursue: Pursue pursue = new Pursue(); pursue.character = this; face1.character = this; pursue.target = target; face1.target = target; //Debug.Log(target); SteeringOutput pursuing = pursue.getSteering(); SteeringOutput facer2 = face1.getSteering(); if (pursuing != null) { linearVelocity += pursuing.linearVelocity * Time.deltaTime; //angularVelocity += pursuing.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Seperation: Seperation seperation = new Seperation(); LookWhereGoing face4 = new LookWhereGoing(); seperation.character = this; face4.character = this; seperation.targets = objectArray; face4.target = target; Debug.Log(target); SteeringOutput seperationing = seperation.getSteering(); SteeringOutput facer3 = face4.getSteering(); //SteeringOutput facing2 = face2.getSteering(); if (seperationing != null) { linearVelocity += seperationing.linearVelocity * Time.deltaTime; angularVelocity += seperationing.angularVelocity * Time.deltaTime; } break; } }
public void SetUp() { _uut = new Seperation(); }
private void Start() { kinematic = GetComponent <Kinematic>(); switch (moveType) { case SteeringType.Pursue: pursueAI = new Pursue(); pursueAI.character = kinematic; pursueAI.target = target; break; case SteeringType.Evade: evadeAI = new Evade(); evadeAI.character = kinematic; evadeAI.target = target; break; case SteeringType.FollowPath: followAI = new PathFollow(); followAI.character = kinematic; followAI.path = pathOfObjects; break; case SteeringType.Seek: seekAI = new Seek(); seekAI.character = kinematic; seekAI.target = target; break; case SteeringType.Flee: fleeAI = new Flee(); fleeAI.character = kinematic; fleeAI.target = target; break; case SteeringType.Seperation: seperationAI = new Seperation(); seperationAI.character = kinematic; seperationAI.targets = seperateObstacles; break; case SteeringType.Arrive: arriveAI = new Arrive(); arriveAI.character = kinematic; arriveAI.target = target; break; case SteeringType.CollisionAvoidance: avoidAI = new CollisionAvoidance(); avoidAI.character = kinematic; avoidAI.targets = collisionTargets; break; case SteeringType.ObstacleAvoidance: obstacleAI = new ObstacleAvoidance(); obstacleAI.character = kinematic; break; case SteeringType.Flocking: flockAI = new Flocker(); break; case SteeringType.None: break; } switch (lookType) { case LookType.Align: alignAI = new Align(); alignAI.character = kinematic; alignAI.target = target; break; case LookType.Face: faceAI = new Face(); faceAI.character = kinematic; faceAI.target = target; break; case LookType.LookWhereGoing: lookAI = new LookWhereGoing(); lookAI.character = kinematic; break; } }