// 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(); }
void FixedUpdate() { Vector3 accel = Vector3.zero; accel += cohesion.getSteering(sensor.targets) * cohesionWeight; accel += separation.getSteering(sensor.targets) * separationWeight; accel += velocityMatch.getSteering(sensor.targets) * velocityMatchWeight; if (accel.magnitude < 0.005f) { accel = wander.getSteering(); } steeringBasics.steer(accel); steeringBasics.lookWhereYoureGoing(); }
void SeparationBehavior() { UpdatePositionRotation(); Separation separation = new Separation(); separation.character = this; separation.targets.Add(target); SteeringOutput separationSteering = separation.getSteering(); if (separationSteering != null) { linearVelocity += separationSteering.linear * Time.deltaTime; angularVelocity += separationSteering.angular * Time.deltaTime; } }
// Update is called once per frame void LateUpdate() { Vector2 targetPos; Vector2 offsetAccel = offsetPursuit.getSteering(target, offset, out targetPos); Vector2 sepAccel = separation.getSteering(sensor.targets); steeringBasics.steer(offsetAccel + sepAccel); /* If we are still arriving then look where we are going, else look the same direction as our formation target */ if (Vector2.Distance(transform.position, targetPos) > groupLookDist) { steeringBasics.lookWhereYoureGoing(); } else { steeringBasics.lookAtDirection(target.rotation); } }
// 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; } }
// 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; }
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 Update() { //Perseguimos al enemigo // con seek aceleracion steeringAgent.UpdateSteering(separation.getSteering()); }