void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case SteeringBehaviors.Arrive: arrive.target = newTarget; if (newTarget != null) { if ((newTarget.transform.position - transform.position).magnitude < 1.5f) { OnArrived?.Invoke(); } } if (newTarget != null) { //steeringUpdate = new SteeringOutput(); steeringUpdate = arrive.getSteering(); } if (steeringUpdate != null) { linear += steeringUpdate.linear * Time.deltaTime; angular += steeringUpdate.angular * Time.deltaTime; } break; } }
// Update is called once per frame protected override void Update() { steeringUpdate = new SteeringOutput(); steeringUpdate.linear = myMoveType.getSteering().linear; steeringUpdate.angular = myRotateType.getSteering().angular; base.Update(); }
// Update is called once per frame void Update() { // update my position and rotation this.transform.position += linearVelocity * Time.deltaTime; Vector3 v = new Vector3(0, angularVelocity, 0); this.transform.eulerAngles += v * Time.deltaTime; // update linear and angular velocities SteeringOutput steering = new SteeringOutput(); if (behaviorType == "Seek" || behaviorType == "seek") { Seek mySeek = new Seek(); mySeek.character = this; mySeek.target = myTarget; steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else if (behaviorType == "Flee" || behaviorType == "flee") { Flee myFlee = new Flee(); myFlee.character = this; myFlee.target = myTarget; steering = myFlee.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else if (behaviorType == "Arrive" || behaviorType == "arrive") { Arrive myArrive = new Arrive(); myArrive.character = this; myArrive.target = myTarget; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } //Align myAlign = new Align(); //myAlign.character = this; //myAlign.target = myTarget; //steering = myAlign.getSteering(); //if (steering != null) //{ // linearVelocity += steering.linear * Time.deltaTime; // angularVelocity += steering.angular * Time.deltaTime; //} }
// Update is called once per frame public void Update() { steeringUpdate = new SteeringOutput(); steeringUpdate.linear = arrive.getSteering().linear; base.Update(); if (Input.GetKeyDown(KeyCode.Return)) { ITask behavior = ConfigureBehavior(); behavior.run(); } }
public void RunTree() { // build tree to get to cheese Task getCheese = buildTree(); getCheese.run(); SteeringOutput mySteering = new SteeringOutput(); mySteering.linear = moveType.getSteering().linear; base.Update(); }
// Update is called once per frame void Update() { //Update pos rot transform.position += linearVelocity * Time.deltaTime; Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0); transform.eulerAngles += angularIncrement; SteeringOutput steering = new SteeringOutput(); //Get Steerings /*if(bIsSeeking) * { * steering = mySeek.getSteering(); * } else * { * steering = myFlee.getSteering(); * }*/ if (bCanArrive) { SteeringOutput _arrvSteering = myArrv.getSteering(); if (_arrvSteering != null) { Debug.Log(_arrvSteering.linear); linearVelocity += _arrvSteering.linear * Time.deltaTime; angularVelocity += _arrvSteering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } if (bDoesAlign) { SteeringOutput _algnSteering = myAlgn.getSteering(); if (_algnSteering != null) { steering.angular += _algnSteering.angular * Time.deltaTime; } else { angularVelocity = 0f; } } //update lin ang vel linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; }
public override Steering getSteering() { Vector3 mTarget = new Vector3(); if (Input.GetButtonDown("Fire1")) { nodoIni = SaberNodo(transform.position); Vector3 cameraPoint = Vector3.zero; RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)) { cameraPoint = hit.point; } Vertice point = SaberNodo(cameraPoint); path = GrafoManager.GetComponent <AEstrella>().hacerAEstrella(g, nodoIni, point); currentNode = 1; } if (path != null) { List <Vector3> nodes = path.getNodes(); mTarget = nodes[currentNode]; if (distance(character, mTarget) <= 1f) { currentNode += 1; if (currentNode == nodes.Count) { currentNode -= 1; //path = null; arrive.target.transform.position = mTarget; return(arrive.getSteering()); } } target.transform.position = mTarget; return(base.getSteering()); } return(new Steering()); }
// Update is called once per frame protected override void Update() { myMoveType.target = myTarget; if (myTarget != null) { if ((myTarget.transform.position - transform.position).magnitude < 1.5f) { OnArrived?.Invoke(); } } if (myTarget != null) { steeringUpdate = myMoveType.getSteering(); } base.Update(); }
// Update is called once per frame protected override void Update() { myMoveType.target = target; if (target != null) { if ((target.transform.position - transform.position).magnitude < 1.5f) { OnArrived?.Invoke(); } } if (target != null) { //steeringUpdate = new SteeringOutput(); controlledSteeringUpdate = myMoveType.getSteering(); } base.Update(); }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case steeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = newTarget; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linear += arriving.linear * Time.deltaTime; angular += arriving.angular * Time.deltaTime; } break; } }
public void createArrive(SteeringOutput steering) { Arrive myArrive = new Arrive { character = this, target = myTarget }; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } }
void StandardBehavior() { UpdatePositionRotation(); if (myTarget != null) { Arrive arrive = new Arrive(); arrive.character = this; arrive.target = myTarget; SteeringOutput arriveSteering = arrive.getSteering(); if (arriveSteering != null) { linearVelocity += arriveSteering.linear * Time.deltaTime; //angularVelocity += arriveSteering.angular * Time.deltaTime; } } if (lookWhereGoing == true) { LookWhereGoing face = new LookWhereGoing(); face.character = this; face.target = faceTarget; SteeringOutput lookSteering = face.getSteering(); if (lookSteering != null) { //linearVelocity += lookSteering.linear * Time.deltaTime; angularVelocity += lookSteering.angular * Time.deltaTime; } return; } if (faceTarget != null) { Face face = new Face(); face.character = this; face.target = faceTarget; SteeringOutput lookSteering = face.getSteering(); if (lookSteering != null) { //linearVelocity += lookSteering.linear * Time.deltaTime; angularVelocity += lookSteering.angular * Time.deltaTime; } } }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case steeringBehaviors.Seek: Seek seek = new Seek(); seek.selectedBoi = this; seek.myBoi = myBoi; 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.selectedBoi = this; flee.myBoi = myBoi; SteeringOutput fleeing = flee.getSteering(); if (fleeing != null) { linearVelocity += fleeing.linearVelocity * Time.deltaTime; angularVelocity += fleeing.angularVelocity * Time.deltaTime; } break; case steeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.selectedBoi = this; arrive.myBoi = myBoi; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linearVelocity += arriving.linearVelocity * Time.deltaTime; angularVelocity += arriving.angularVelocity * Time.deltaTime; } break; } }
// Update is called once per frame void Update() { // update my position and rotation this.transform.position += linearVelocity * Time.deltaTime; Vector3 v = new Vector3(0, angularVelocity, 0); // TODO - don't make a new Vector3 every update you silly person this.transform.eulerAngles += v * Time.deltaTime; // update linear and angular velocities SteeringOutput steering = new SteeringOutput(); //Seek mySeek = new Seek(); //mySeek.character = this; //mySeek.target = myTarget; //steering = mySeek.getSteering(); //linearVelocity += steering.linear * Time.deltaTime; //angularVelocity += steering.angular * Time.deltaTime; Arrive myArrive = new Arrive(); myArrive.character = this; myArrive.target = myTarget; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } //Align myAlign = new Align(); //myAlign.character = this; //myAlign.target = myTarget; //steering = myAlign.getSteering(); //if (steering != null) //{ // linearVelocity += steering.linear * Time.deltaTime; // angularVelocity += steering.angular * Time.deltaTime; //} }
// Update is called once per frame void Update() { /* * My Implementation of flocking */ //Get the average group velocity and position Vector3 averagePosition = new Vector3(); Vector3 averageVelocity = new Vector3(); foreach (GameObject character in characters) { averagePosition += character.transform.position; averageVelocity += character.GetComponent <SteeringCharacter>().velocity; } averagePosition *= 1.0f / characters.Count; averageVelocity *= 1.0f / characters.Count; //averagePosition = targetObject.transform.position; //Set to arrive at the average position arrivalBehavior.target = averagePosition; //Set to match the average velocity velocityMatchBehavior.target = averageVelocity; //Loop through every character foreach (GameObject character in characters) { SteeringCharacter thisChar = character.GetComponent <SteeringCharacter>(); arrivalBehavior.character = thisChar; separationBehavior.character = thisChar; velocityMatchBehavior.character = thisChar; SteeringOutput arrivalSteering = arrivalBehavior.getSteering(); SteeringOutput separationSteering = separationBehavior.getSteering(); SteeringOutput velocityMatchSteering = velocityMatchBehavior.getSteering(); thisChar.steering = new SteeringOutput(); //Combine all steering behaviors thisChar.steering.linear = arrivalSteering.linear + separationSteering.linear + velocityMatchSteering.linear; } }
void StandardBehavior() { UpdatePositionRotation(); switch (behavior) { case steeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = target; SteeringOutput seekSteering = seek.getSteering(); if (seekSteering != null) { linearVelocity += seekSteering.linear * Time.deltaTime; angularVelocity += seekSteering.angular * Time.deltaTime; } break; case steeringBehaviors.Flee: Flee flee = new Flee(); flee.character = this; flee.target = target; SteeringOutput fleeSteering = flee.getSteering(); if (fleeSteering != null) { linearVelocity += fleeSteering.linear * Time.deltaTime; angularVelocity += fleeSteering.angular * Time.deltaTime; } break; case steeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = target; SteeringOutput arriveSteering = arrive.getSteering(); if (arriveSteering != null) { linearVelocity += arriveSteering.linear * Time.deltaTime; angularVelocity += arriveSteering.angular * Time.deltaTime; } break; case steeringBehaviors.Align: Align align = new Align(); align.character = this; align.target = target; SteeringOutput alignSteering = align.getSteering(); if (alignSteering != null) { linearVelocity += alignSteering.linear * Time.deltaTime; angularVelocity += alignSteering.angular * Time.deltaTime; } break; case steeringBehaviors.Face: Face face = new Face(); face.character = this; face.target = target; SteeringOutput faceSteering = face.getSteering(); if (faceSteering != null) { linearVelocity += faceSteering.linear * Time.deltaTime; angularVelocity += faceSteering.angular * Time.deltaTime; } break; case steeringBehaviors.LookWhereGoing: LookWhereGoing look = new LookWhereGoing(); look.character = this; look.target = target; SteeringOutput lookSteering = look.getSteering(); if (lookSteering != null) { linearVelocity += lookSteering.linear * Time.deltaTime; angularVelocity += lookSteering.angular * Time.deltaTime; } break; } }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case steeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = newTarget; SteeringOutput seeking = seek.getSteering(); if (seeking != null) { linear += seeking.linear * Time.deltaTime; angular += seeking.angular * Time.deltaTime; } break; case steeringBehaviors.Flee: Flee flee = new Flee(); flee.character = this; flee.target = newTarget; SteeringOutput fleeing = flee.getSteering(); if (fleeing != null) { linear += fleeing.linear * Time.deltaTime; angular += fleeing.angular * Time.deltaTime; } break; case steeringBehaviors.Align: Align align = new Align(); align.character = this; align.target = newTarget; SteeringOutput aligning = align.getSteering(); if (aligning != null) { linear += aligning.linear * Time.deltaTime; angular += aligning.angular * Time.deltaTime; } break; case steeringBehaviors.Face: Face face = new Face(); face.character = this; face.target = newTarget; SteeringOutput facing = face.getSteering(); if (facing != null) { linear += facing.linear * Time.deltaTime; angular += facing.angular * Time.deltaTime; } break; case steeringBehaviors.LookWhereGoing: LookWhereGoing look = new LookWhereGoing(); look.character = this; look.target = newTarget; SteeringOutput looking = look.getSteering(); if (looking != null) { linear += looking.linear * Time.deltaTime; angular += looking.angular * Time.deltaTime; } break; case steeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = newTarget; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linear += arriving.linear * Time.deltaTime; angular += arriving.angular * Time.deltaTime; } break; case steeringBehaviors.PathFollow: follow.character = this; lookwg.character = this; follow.path = path; lookwg.target = newTarget; SteeringOutput following = follow.getSteering(); SteeringOutput lookingwg = lookwg.getSteering(); if (following != null) { linear += following.linear * Time.deltaTime; // angular += lookingwg.angular* Time.deltaTime; } break; case steeringBehaviors.Pursue: Pursue pursue = new Pursue(); LookWhereGoing PursuelookWhereGoing = new LookWhereGoing(); pursue.character = this; PursuelookWhereGoing.character = this; pursue.target = newTarget; PursuelookWhereGoing.target = newTarget; SteeringOutput pursuing = pursue.getSteering(); SteeringOutput pursuelookingWhereGoing = PursuelookWhereGoing.getSteering(); if (pursuing != null) { linear += pursuing.linear * Time.deltaTime; angular += pursuing.angular * Time.deltaTime; } break; case steeringBehaviors.Separate: Separate separate = new Separate(); LookWhereGoing lookWhereGoing = new LookWhereGoing(); separate.character = this; lookWhereGoing.character = this; separate.targets = targets; lookWhereGoing.target = newTarget; SteeringOutput lookingWhereGoing = lookWhereGoing.getSteering(); SteeringOutput separating = separate.getSteering(); if (separating != null) { linear += separating.linear * Time.deltaTime; angular += separating.angular * Time.deltaTime; } break; case steeringBehaviors.CollisionAvoidance: CollisionAvoidance avoid = new CollisionAvoidance(); LookWhereGoing AvoidlookWhereGoing = new LookWhereGoing(); avoid.character = this; AvoidlookWhereGoing.character = this; avoid.targets = targets; AvoidlookWhereGoing.target = newTarget; SteeringOutput AvoidlookingWhereGoing = AvoidlookWhereGoing.getSteering(); SteeringOutput avoiding = avoid.getSteering(); if (avoiding != null) { linear += avoiding.linear * Time.deltaTime; angular += avoiding.angular * Time.deltaTime; } break; case steeringBehaviors.ObstacleAvoidance: ObstacleAvoidance obAvoid = new ObstacleAvoidance(); LookWhereGoing obAvoidlookWhereGoing = new LookWhereGoing(); obAvoid.character = this; obAvoidlookWhereGoing.character = this; obAvoid.target = newTarget; obAvoidlookWhereGoing.target = newTarget; SteeringOutput obAvoiding = obAvoid.getSteering(); SteeringOutput obAvoidlookingWhereGoing = obAvoidlookWhereGoing.getSteering(); if (obAvoiding != null) { linear += obAvoiding.linear * Time.deltaTime; angular += obAvoiding.angular * Time.deltaTime; } break; } }
void Update() { //Perseguimos al enemigo // con arrive accels steeringAgent.UpdateSteering(arrive.getSteering()); }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case SteeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = newTarget; SteeringOutput seeking = seek.getSteering(); if (seeking != null) { linear += seeking.linear * Time.deltaTime; angular += seeking.angular * Time.deltaTime; } break; case SteeringBehaviors.Flee: Flee flee = new Flee(); flee.character = this; flee.target = newTarget; SteeringOutput fleeing = flee.getSteering(); if (fleeing != null) { linear += fleeing.linear * Time.deltaTime; angular += fleeing.angular * Time.deltaTime; } break; case SteeringBehaviors.Align: Align align = new Align(); align.character = this; align.target = newTarget; SteeringOutput aligning = align.getSteering(); if (aligning != null) { linear += aligning.linear * Time.deltaTime; angular += aligning.angular * Time.deltaTime; } break; case SteeringBehaviors.Face: Face face = new Face(); face.character = this; face.target = newTarget; SteeringOutput facing = face.getSteering(); if (facing != null) { linear += facing.linear * Time.deltaTime; angular += facing.angular * Time.deltaTime; } break; case SteeringBehaviors.LookWhereGoing: LookWhereGoing look = new LookWhereGoing(); look.character = this; look.target = newTarget; SteeringOutput looking = look.getSteering(); if (looking != null) { linear += looking.linear * Time.deltaTime; angular += looking.angular * Time.deltaTime; } break; case SteeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = newTarget; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linear += arriving.linear * Time.deltaTime; angular += arriving.angular * Time.deltaTime; } break; case SteeringBehaviors.PathFollow: follow.character = this; lookwg.character = this; follow.path = myPath; lookwg.target = newTarget; SteeringOutput following = follow.getSteering(); SteeringOutput lookingwg = lookwg.getSteering(); if (following != null) { linear += following.linear * Time.deltaTime; // angular += lookingwg.angular* Time.deltaTime; } break; case SteeringBehaviors.Pursue: Pursue pursue = new Pursue(); LookWhereGoing PursuelookWhereGoing = new LookWhereGoing(); pursue.character = this; PursuelookWhereGoing.character = this; pursue.target = newTarget; PursuelookWhereGoing.target = newTarget; SteeringOutput pursuing = pursue.getSteering(); SteeringOutput pursuelookingWhereGoing = PursuelookWhereGoing.getSteering(); if (pursuing != null) { if (pursuing.linear.magnitude <= maxSpeed) { linear += pursuing.linear * Time.deltaTime; } angular += pursuing.angular * Time.deltaTime; } break; case SteeringBehaviors.Separate: Separation separate = new Separation(); LookWhereGoing lookWhereGoing = new LookWhereGoing(); separate.character = this; lookWhereGoing.character = this; separate.targets = targets; lookWhereGoing.target = newTarget; SteeringOutput lookingWhereGoing = lookWhereGoing.getSteering(); SteeringOutput separating = separate.getSteering(); if (separating != null) { linear += separating.linear * Time.deltaTime; angular += separating.angular * Time.deltaTime; } break; case SteeringBehaviors.CollisionAvoidance: CollisionAvoidance avoid = new CollisionAvoidance(); LookWhereGoing AvoidlookWhereGoing = new LookWhereGoing(); avoid.character = this; AvoidlookWhereGoing.character = this; avoid.targets = targets; AvoidlookWhereGoing.target = newTarget; SteeringOutput AvoidlookingWhereGoing = AvoidlookWhereGoing.getSteering(); SteeringOutput avoiding = avoid.getSteering(); if (avoiding != null) { linear += avoiding.linear * Time.deltaTime; angular += avoiding.angular * Time.deltaTime; } break; case SteeringBehaviors.ObstacleAvoidance: ObstacleAvoidance obAvoid = new ObstacleAvoidance(); LookWhereGoing obAvoidlookWhereGoing = new LookWhereGoing(); obAvoid.character = this; obAvoidlookWhereGoing.character = this; obAvoid.target = newTarget; obAvoidlookWhereGoing.target = newTarget; SteeringOutput obAvoiding = obAvoid.getSteering(); SteeringOutput obAvoidlookingWhereGoing = obAvoidlookWhereGoing.getSteering(); if (obAvoiding != null) { if (obAvoiding.linear.magnitude <= maxSpeed) { linear += obAvoiding.linear * Time.deltaTime; } angular += obAvoiding.angular * Time.deltaTime; } break; case SteeringBehaviors.Flocking: Separation sepFlock = new Separation(); Arrive arriveFlock = new Arrive(); LookWhereGoing lwgFlock = new LookWhereGoing(); BlendedSteering mySteering = new BlendedSteering(); Kinematic[] kBirds; sepFlock.character = this; GameObject[] goBirds = GameObject.FindGameObjectsWithTag("Pengu"); kBirds = new Kinematic[goBirds.Length - 1]; int j = 0; for (int i = 0; i < goBirds.Length - 1; i++) { if (goBirds[i] == this) { continue; } goBirds[i].GetComponent <Animator>().SetInteger("Walk", 1); kBirds[j++] = goBirds[i].GetComponent <Kinematic>(); } sepFlock.targets = kBirds; arriveFlock.character = this; //Debug.Log(arriveFlock.character); arriveFlock.target = newTarget; //Debug.Log(arriveFlock.target); lwgFlock.character = this; lwgFlock.target = newTarget; mySteering.behaviors = new BehaviorAndWeight[3]; mySteering.behaviors[0] = new BehaviorAndWeight(); mySteering.behaviors[0].behavior = sepFlock; mySteering.behaviors[0].weight = 1f; mySteering.behaviors[1] = new BehaviorAndWeight(); mySteering.behaviors[1].behavior = arriveFlock; mySteering.behaviors[1].weight = 1f; mySteering.behaviors[2] = new BehaviorAndWeight(); mySteering.behaviors[2].behavior = lwgFlock; mySteering.behaviors[2].weight = 1f; ObstacleAvoidance myAvoid = new ObstacleAvoidance(); myAvoid.character = this; myAvoid.target = newTarget; myAvoid.flee = true; BlendedSteering myHighPrioritySteering = new BlendedSteering(); myHighPrioritySteering.behaviors = new BehaviorAndWeight[1]; myHighPrioritySteering.behaviors[0] = new BehaviorAndWeight(); myHighPrioritySteering.behaviors[0].behavior = myAvoid; myHighPrioritySteering.behaviors[0].weight = 0.1f; myAdvancedSteering.groups = new BlendedSteering[2]; myAdvancedSteering.groups[0] = new BlendedSteering(); myAdvancedSteering.groups[0] = myHighPrioritySteering; myAdvancedSteering.groups[1] = new BlendedSteering(); myAdvancedSteering.groups[1] = mySteering; //steeringUpdate = mySteering.getSteering(); avoidObstacles = true; if (!avoidObstacles) { steeringUpdate = mySteering.getSteering(); if (steeringUpdate != null) { linear += steeringUpdate.linear * Time.deltaTime; angular += steeringUpdate.angular * Time.deltaTime; } } else { steeringUpdate = myAdvancedSteering.getSteering(); if (steeringUpdate != null) { linear += steeringUpdate.linear * Time.deltaTime; angular += steeringUpdate.angular * Time.deltaTime; } } break; case SteeringBehaviors.PathFinder: SteeringOutput lwyger = myRotateType.getSteering(); linear += myMoveType.getSteering().linear *Time.deltaTime; angular += myMoveType.getSteering().angular *Time.deltaTime; break; } }
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; } }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case steeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = newTarget; SteeringOutput seeking = seek.getSteering(); if (seeking != null) { linear += seeking.linear * Time.deltaTime; angular += seeking.angular * Time.deltaTime; } break; case steeringBehaviors.Flee: Flee flee = new Flee(); flee.character = this; flee.target = newTarget; SteeringOutput fleeing = flee.getSteering(); if (fleeing != null) { linear += fleeing.linear * Time.deltaTime; angular += fleeing.angular * Time.deltaTime; } break; case steeringBehaviors.Align: Align align = new Align(); align.character = this; align.target = newTarget; SteeringOutput aligning = align.getSteering(); if (aligning != null) { linear += aligning.linear * Time.deltaTime; angular += aligning.angular * Time.deltaTime; } break; case steeringBehaviors.Face: Face face = new Face(); face.character = this; face.target = newTarget; SteeringOutput facing = face.getSteering(); if (facing != null) { linear += facing.linear * Time.deltaTime; angular += facing.angular * Time.deltaTime; } break; case steeringBehaviors.LookWhereGoing: LookWhereGoing look = new LookWhereGoing(); look.character = this; look.target = newTarget; SteeringOutput looking = look.getSteering(); if (looking != null) { linear += looking.linear * Time.deltaTime; angular += looking.angular * Time.deltaTime; } break; case steeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = newTarget; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linear += arriving.linear * Time.deltaTime; angular += arriving.angular * Time.deltaTime; } break; case steeringBehaviors.PathFollow: follow.character = this; follow.path = path; SteeringOutput following = follow.getSteering(); if (following != null) { linear += following.linear * Time.deltaTime; } break; case steeringBehaviors.Pursue: Pursue pursue = new Pursue(); pursue.target = newTarget; pursue.character = this; SteeringOutput pursuing = pursue.getSteering(); if (pursuing != null) { linear += pursuing.linear * Time.deltaTime; angular += pursuing.angular * Time.deltaTime; } break; case steeringBehaviors.Separate: Separate separate = new Separate(); separate.character = this; separate.targets = targets; SteeringOutput separating = separate.getSteering(); if (separating != null) { linear += separating.linear * Time.deltaTime; angular += separating.angular * Time.deltaTime; } break; } }
//en este caso la accion es actualizar la acelaracion del usuario public override void DoAction() { steeringAgent.UpdateSteering(arrive.getSteering()); }
// Update is called once per frame void Update() { if (behaviorNum != 0) { // update my position and rotation this.transform.position += linearVelocity * Time.deltaTime; Vector3 v = new Vector3(0, angularVelocity, 0); this.transform.eulerAngles += v * Time.deltaTime; } // update linear and angular velocities SteeringOutput steering = new SteeringOutput(); // Seek: target is "alsoMyTargetForPursueTho" if (behaviorNum == 1) { Seek mySeek = new Seek(); text.text = "Seek"; mySeek.target = alsoMyTargetForPursueTho; mySeek.character = this; steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } // Flee else if (behaviorNum == 2) { Flee myFlee = new Flee(); text.text = "Flee"; myFlee.character = this; myFlee.target = myTarget; steering = myFlee.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } // Arrive else if (behaviorNum == 3) { Arrive myArrive = new Arrive(); text.text = "Arrive"; myArrive.character = this; myArrive.target = myTarget; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } // Align else if (behaviorNum == 4) { Align myAlign = new Align(); text.text = "Align"; myAlign.character = this; myAlign.target = myTarget; steering = myAlign.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Face else if (behaviorNum == 5) { Face myFace = new Face(); text.text = "Face"; myFace.character = this; myFace.target = myTarget; steering = myFace.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Look where you're going else if (behaviorNum == 6) { LWYG myLook = new LWYG(); text.text = "LWYG"; myLook.character = this; steering = myLook.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Path following else if (behaviorNum == 7) { text.text = "Path Follow"; myPathFollow.character = this; myPathFollow.path = pathToFollow; steering = myPathFollow.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Pursue else if (behaviorNum == 8) { Pursue myPursue = new Pursue(); text.text = "Pursue"; myPursue.character = this; myPursue.target = alsoMyTargetForPursueTho; steering = myPursue.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Seperate else if (behaviorNum == 9) { text.text = "Seperate"; mySeperate.character = this; mySeperate.targets = targetsForSeperate; steering = mySeperate.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Collision Avoidance else if (behaviorNum == 10) { text.text = "Collision Avoidance"; CollisionAvoidance myCollision = new CollisionAvoidance(); myCollision.character = this; myCollision.targets = targetsForSeperate; steering = myCollision.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Obstacle Avoidance else if (behaviorNum == 11) { text.text = "Obstacle Avoidance"; ObstacleAvoid myObstacleAvoid = new ObstacleAvoid(); myObstacleAvoid.character = this; myObstacleAvoid.target = myTarget; steering = myObstacleAvoid.GetSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } }
// Update is called once per frame void Update() { transform.position += linearVelocity * Time.deltaTime; // adding angular velocity to current transform rotation y component transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0); // control to switch to proper steering behavior if (!arrive) { Seek mySeek = new Seek(); mySeek.ai = this; // if seek is false set seek property on class to false to activate flee if (!seek) { mySeek.seek = false; } else { mySeek.seek = true; } mySeek.target = target; SteeringOutput steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } } else { Arrive myArrive = new Arrive(); myArrive.ai = this; myArrive.target = target; SteeringOutput steering = myArrive.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } /* commented out after turn in - non-relevant code for assignment was throwing errors * if (align) * { * Align myAlign = new Align(); * myAlign.ai = this; * myAlign.target = target; * SteeringOutput steering = myAlign.getSteering(); * if (steering != null) * { * linearVelocity += steering.linear * Time.deltaTime; * angularVelocity += steering.angular * Time.deltaTime; * } * } * if (lookWhereGoing && !align) * { * LookWhereGoing myLook = new LookWhereGoing(); * myLook.ai = this; * target = new GameObject(); * SteeringOutput steering = myLook.getSteering(); * linearVelocity += steering.linear * Time.deltaTime; * angularVelocity += steering.angular * Time.deltaTime; * Destroy(target); * } */ }
// Update is called once per frame void Update() { // update my position and rotation this.transform.position += linearVelocity * Time.deltaTime; Vector3 v = new Vector3(0, angularVelocity, 0); // TODO - don't make a new Vector3 every update you silly person this.transform.eulerAngles += v * Time.deltaTime; // update linear and angular velocities SteeringOutput steering = new SteeringOutput(); if (behaviorType == "Seek" || behaviorType == "seek") { Seek mySeek = new Seek(); mySeek.character = this; mySeek.target = myTarget; steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else if (behaviorType == "Flee" || behaviorType == "flee") { Flee myFlee = new Flee(); myFlee.character = this; myFlee.target = myTarget; steering = myFlee.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else if (behaviorType == "Arrive" || behaviorType == "arrive") { Arrive myArrive = new Arrive(); myArrive.character = this; myArrive.target = myTarget; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } else if (behaviorType == "Align" || behaviorType == "align") { Align myAlign = new Align(); myAlign.character = this; myAlign.target = myTarget; steering = myAlign.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } else if (behaviorType == "Face" || behaviorType == "face") { Face myFace = new Face(); myFace.character = this; myFace.target = myTarget; steering = myFace.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } else if (behaviorType == "LWYG" || behaviorType == "lwyg" || behaviorType == "Lwyg") { LWYG myLook = new LWYG(); myLook.character = this; steering = myLook.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } }
// Update is called once per frame void Update() { //Update pos rot transform.position += linearVelocity * Time.deltaTime; Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0); if (float.IsNaN(angularIncrement.y)) { } else { transform.eulerAngles += angularIncrement; } //Debug.Log(angularIncrement); SteeringOutput steering = new SteeringOutput(); //Get Steerings if (bIsSeeking) { steering = mySeek.getSteering(); } else { //steering = myFlee.getSteering(); } if (bCanArrive) { SteeringOutput _arrvSteering = myArrv.getSteering(); if (_arrvSteering != null) { linearVelocity += _arrvSteering.linear * Time.deltaTime; angularVelocity += _arrvSteering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } if (bDoesAlign) { SteeringOutput _algnSteering = myAlgn.getSteering(); if (_algnSteering != null) { steering.angular += _algnSteering.angular * Time.deltaTime; } else { angularVelocity = 0f; } } if (bDoesFace) { SteeringOutput _faceSteering = myFace.getSteering(); if (_faceSteering != null) { angularVelocity += _faceSteering.angular * Time.deltaTime; } } if (bDoesLookWhereGoing) { SteeringOutput _lwygSteering = myLWYG.getSteering(); if (_lwygSteering != null) { angularVelocity += _lwygSteering.angular * Time.deltaTime; } } if (bDoesFollowPath) { SteeringOutput _fpthSteering = myFPth.getSteering(); if (_fpthSteering != null) { linearVelocity += _fpthSteering.linear * Time.deltaTime; } } //update lin ang vel linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; }
// Update is called once per frame protected virtual void Update() { //Update pos rot transform.position += linearVelocity * Time.deltaTime; Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0); if (float.IsNaN(angularIncrement.y)) { } else { transform.eulerAngles += angularIncrement; } //Debug.Log(angularIncrement); SteeringOutput steering = new SteeringOutput(); //Get Steerings if (bIsSeeking) { steering = mySeek.getSteering(); } else { //steering = myFlee.getSteering(); } if (bCanArrive) { SteeringOutput _arrvSteering = myArrv.getSteering(); if (_arrvSteering != null) { linearVelocity += _arrvSteering.linear * Time.deltaTime; angularVelocity += _arrvSteering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } if (bDoesAlign) { SteeringOutput _algnSteering = myAlgn.getSteering(); if (_algnSteering != null) { steering.angular += _algnSteering.angular * Time.deltaTime; } else { angularVelocity = 0f; } } if (bDoesFace) { SteeringOutput _faceSteering = myFace.getSteering(); if (_faceSteering != null) { angularVelocity += _faceSteering.angular * Time.deltaTime; } } if (bDoesLookWhereGoing) { SteeringOutput _lwygSteering = myLWYG.getSteering(); if (_lwygSteering != null) { angularVelocity += _lwygSteering.angular * Time.deltaTime; } } if (bDoesFollowPath) { SteeringOutput _fpthSteering = myFPth.getSteering(); if (_fpthSteering != null) { linearVelocity += _fpthSteering.linear * Time.deltaTime; } } if (bDoesSeparate) { SteeringOutput _seprSteering = mySepr.getSteering(); if (_seprSteering != null) { linearVelocity += _seprSteering.linear * Time.deltaTime; } } if (bDoesPursue) { SteeringOutput _prsuSteering = myPrsu.getSteering(); if (_prsuSteering != null) { linearVelocity += _prsuSteering.linear * Time.deltaTime; } } if (bDoesAvoidColl) { SteeringOutput _clAvSteering = myClAv.getSteering(); if (_clAvSteering != null) { linearVelocity += _clAvSteering.linear * Time.deltaTime; } } if (bDoesObstAvoid) { SteeringOutput _obAvSteering = myObAv.getSteering(); if (_obAvSteering != null) { linearVelocity += _obAvSteering.linear * Time.deltaTime; } } ///Check for controlled steering updates if (controlledSteeringUpdate != null) { linearVelocity += controlledSteeringUpdate.linear * Time.deltaTime; angularVelocity += controlledSteeringUpdate.angular * Time.deltaTime; } //update lin ang vel linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; }
// Update is called once per frame void Update() { myTarget = GameObject.Find("Player"); // update my position and rotation this.transform.position += linearVelocity * Time.deltaTime; Vector3 v = new Vector3(0, angularVelocity, 0); // TODO - don't make a new Vector3 every update you silly person this.transform.eulerAngles += v * Time.deltaTime; // update linear and angular velocities SteeringOutput steering = new SteeringOutput(); //TODO add switch statement for different move type (6 behaviours) if (flee) { Seek mySeek = new Seek { character = this, target = myTarget }; mySeek.flee = true; steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else if (seek) { Seek mySeek = new Seek { character = this, target = myTarget }; steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else if (arrive) { Arrive myArrive = new Arrive { character = this, target = myTarget }; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } else if (face) { Face myAlign = new Face { character = this, target = myTarget }; steering = myAlign.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } else if (look) { LookWhereYoureGoing myAlign = new LookWhereYoureGoing { character = this, target = myTarget }; steering = myAlign.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } else if (align) { Align myAlign = new Align { character = this, target = myTarget }; steering = myAlign.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } }
// Update is called once per frame void Update() { if (behaviorNum != 0) { // update my position and rotation this.transform.position += linearVelocity * Time.deltaTime; Vector3 v = new Vector3(0, angularVelocity, 0); this.transform.eulerAngles += v * Time.deltaTime; } // update linear and angular velocities SteeringOutput steering = new SteeringOutput(); // Seek: target is "alsoMyTargetForPursueTho" if (behaviorNum == 1) { text.text = "Seek"; Seek mySeek = new Seek(); mySeek.target = alsoMyTargetForPursueTho; mySeek.character = this; steering = mySeek.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } // Flee else if (behaviorNum == 2) { Flee myFlee = new Flee(); text.text = "Flee"; myFlee.character = this; myFlee.target = myTarget; steering = myFlee.getSteering(); linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } // Arrive else if (behaviorNum == 3) { Arrive myArrive = new Arrive(); text.text = "Arrive"; myArrive.character = this; myArrive.target = myTarget; steering = myArrive.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { linearVelocity = Vector3.zero; } } // Align else if (behaviorNum == 4) { Align myAlign = new Align(); text.text = "Align"; myAlign.character = this; myAlign.target = myTarget; steering = myAlign.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Face else if (behaviorNum == 5) { Face myFace = new Face(); text.text = "Face"; myFace.character = this; myFace.target = myTarget; steering = myFace.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Look where you're going else if (behaviorNum == 6) { LWYG myLook = new LWYG(); text.text = "LWYG"; myLook.character = this; steering = myLook.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Path following else if (behaviorNum == 7) { text.text = "Path Follow"; myPathFollow.character = this; myPathFollow.path = pathToFollow; steering = myPathFollow.getSteering(); if (steering != null) { if (linearVelocity.magnitude > 2) { linearVelocity = linearVelocity.normalized * 2; } linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Pursue else if (behaviorNum == 8) { Pursue myPursue = new Pursue(); text.text = "Pursue"; myPursue.character = this; myPursue.target = alsoMyTargetForPursueTho; steering = myPursue.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Seperate else if (behaviorNum == 9) { text.text = "Seperate"; mySeperate.character = this; mySeperate.targets = targetsForSeperate; steering = mySeperate.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Collision Avoidance else if (behaviorNum == 10) { text.text = "Collision Avoidance"; CollisionAvoidance myCollision = new CollisionAvoidance(); myCollision.character = this; myCollision.targets = targetsForSeperate; steering = myCollision.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Obstacle Avoidance else if (behaviorNum == 11) { text.text = "Obstacle Avoidance"; ObstacleAvoid myObstacleAvoid = new ObstacleAvoid(); myObstacleAvoid.character = this; myObstacleAvoid.target = myTarget; steering = myObstacleAvoid.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } // Flocking else if (behaviorNum == 12) { text.text = "Flocking"; if (!setUp) { // BehaviorAndWeight1 : Seperate BehaviorAndWeight behavior1 = new BehaviorAndWeight(); Seperate mySeperate = new Seperate(); mySeperate.character = this; GameObject[] birds = GameObject.FindGameObjectsWithTag("Bird"); Kinematic[] kBirds = new Kinematic[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 <Kinematic>(); } mySeperate.targets = kBirds; behavior1.behavior = mySeperate; behavior1.weight = 10f; // BehaviorAndWeight2 : Arrive BehaviorAndWeight behavior2 = new BehaviorAndWeight(); Arrive myArrive = new Arrive(); myArrive.character = this; myArrive.target = myTarget; behavior2.behavior = myArrive; behavior2.weight = 10f; // BehaviorAndWeight3 : Align BehaviorAndWeight behavior3 = new BehaviorAndWeight(); Align myAlign = new Align(); myAlign.character = this; myAlign.target = myTarget; behavior3.behavior = myAlign; behavior3.weight = 3f; // BehaviorAndWeight4 : ObstacleAvoidance BehaviorAndWeight behavior4 = new BehaviorAndWeight(); ObstacleAvoid myObstacle = new ObstacleAvoid(); myObstacle.character = this; myObstacle.target = myTargetObstacle; // Does this make sense? behavior4.behavior = myObstacle; behavior4.weight = 1f; // Lower priority steering behaviors: Arrive, Align, & Seperate BlendedSteeringDemo myBlended = new BlendedSteeringDemo(); myBlended.behaviors = new BehaviorAndWeight[3]; myBlended.behaviors[0] = new BehaviorAndWeight(); myBlended.behaviors[0] = behavior1; myBlended.behaviors[1] = new BehaviorAndWeight(); myBlended.behaviors[1] = behavior2; myBlended.behaviors[2] = new BehaviorAndWeight(); myBlended.behaviors[2] = behavior3; // Higher priority steering behavior: Obstacle avoidance BlendedSteeringDemo myBlendedAvoid = new BlendedSteeringDemo(); myBlendedAvoid.behaviors = new BehaviorAndWeight[1]; myBlendedAvoid.behaviors[0] = new BehaviorAndWeight(); myBlendedAvoid.behaviors[0] = behavior4; // Initialize myPriority's array of groups with two groups myPriority.groups = new BlendedSteeringDemo[2]; myPriority.groups[0] = new BlendedSteeringDemo(); myPriority.groups[0] = myBlendedAvoid; myPriority.groups[1] = new BlendedSteeringDemo(); myPriority.groups[1] = myBlended; setUp = true; } steering = myPriority.getSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case steeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = newTarget; 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 = newTarget; 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 = newTarget; 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 = newTarget; 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 = newTarget; 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 = newTarget; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linearVelocity += arriving.linearVelocity * Time.deltaTime; angularVelocity += arriving.angularVelocity * Time.deltaTime; } break; } }