public static Steering GetSteering(Agent target, Agent npc, Vector3 behind, float slowingRadius, float maxAccel, float threshold, float decayCoefficient, bool visibleRays, float arrivePriority, float separationPriority, float evadePriority) { Steering steering = new Steering(); steering.linear += Arrive.GetSteering(behind, npc, slowingRadius, maxAccel).linear *arrivePriority; steering.linear += Separation.GetSteering(npc, threshold, decayCoefficient, maxAccel, visibleRays).linear *separationPriority; if (OnLeaderSight(target, npc)) { steering.linear += Evade.GetSteering(target, npc, maxAccel, Vector3.Distance(target.position, npc.position) * maxAccel, true).linear *evadePriority; } return(steering); }
public static SteeringOutput GetSteering(KinematicState ownKS, SArrive arriveInfo, SObstacleAvoidance obstacleInfo, ref bool obstacleAvoided) { SteeringOutput obstacleAvoidSteering = ObstacleAvoidance.GetSteering(ownKS, obstacleInfo); if (obstacleAvoidSteering != NULL_STEERING) { obstacleAvoided = true; return(obstacleAvoidSteering); } obstacleAvoided = false; return(Arrive.GetSteering(ownKS, arriveInfo)); }
/// <summary> /// returns true while still following a path. Returns false when it arrives /// </summary> /// <returns></returns> public bool DoFollowPathStep() { RequestPath(GetTarget().transform); var followingPath = true; var pos2D = Path.Vector3ToVector2(_myTransform.position); if (_path == null) // we are still waiting for the path to be calculated { return(true); // we are technically still following the path (we have not arrived) } if (_pathIndex > _path.TurnBoundaries.Length || _path.FinishLineIndex == -1) { _pathIndex = 0; return(true); } // loops through the turn boundaries till it founds the last boundary it has crossed. // This solves the pathing problem if we move through several turn boundaries for each turn. while (_path.TurnBoundaries[_pathIndex].HasCrossedLine(pos2D)) { // we arrived at the end of the path if (_pathIndex >= _path.FinishLineIndex) { break; } _pathIndex++; } if (Vector3.Distance(transform.position, GetTarget().position) < 1f) { GetComponent <Rigidbody>().velocity = Vector3.zero; followingPath = false; } // rotate and move the unit to the next point if (followingPath) { var acc = _arrive.GetSteering(_path.LookPoints[_pathIndex]); if (Math.Abs(acc.x) < 0.01f && Math.Abs(acc.z) < 0.01f) // something went wrong with the pathfinding and we are stuck. Do a new plan. { if (GetTarget() != null) { RequestPath(GetTarget().transform, true); } } _steering.Steer(acc); _steering.LookWhereYoureGoing(); } return(followingPath); }
public override Steering GetSteering() { if (!active) { return(new Steering()); } // Debug.Log ("Vamos a actuar con una orientacion de " + orientation); Steering force = Arrive.GetSteering(target, npc, npc.exteriorRadius, maxAccel) + Align.GetSteering(orientation, npc, npc.interiorAngle, npc.exteriorAngle, 0.1f, visibleRays); /* if (Util.HorizontalDistance(target,npc.position) <= 0.1f && Mathf.Abs(orientation - npc.orientation) <= 1.1f) * GoalReached();*/ // Debug.Log ("El GoForm contribuye al angular en " + force.angular); return(force); }
private void Update() { if (Input.GetKeyDown(KeyCode.Return)) { door.Begin(); Behave(); } //Steering stuff SteeringOutput movementSteering; //Update position and rotation transform.position += linearVelocity * Time.deltaTime; Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0); transform.eulerAngles += angularIncrement; movementSteering = arrive.GetSteering(); if (movementSteering != null) { linearVelocity += movementSteering.linear * Time.deltaTime; } kinematic.GetData(movementSteering); }
public static Steering GetSteering(Vector3 target, Agent npc, float orientation, float slowingRadius, float maxAccel, bool visibleRays) { return(Arrive.GetSteering(target, npc, npc.exteriorRadius, maxAccel) + Align.GetSteering(orientation, npc, npc.interiorAngle, npc.exteriorAngle, 0.1f, visibleRays)); }
// 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; } }
// Update is called once per frame void Update() { 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); //dynamicSteering steering = new Seek(); // 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; } 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 && !face) { LookWhereGoing myLook = new LookWhereGoing(); myLook.ai = this; myLook.target = target; SteeringOutput steering = myLook.GetSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } else { Debug.Log("Returning Null"); } } if (!lookWhereGoing && !align && face) { Face myFace = new Face(); myFace.ai = this; myFace.target = target; SteeringOutput steering = myFace.GetSteering(); if (steering != null) { linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steering.angular * Time.deltaTime; } } }
// Update is called once per frame public override void Update() { mySteering = new SteeringOutput(); mySteering.linear = arrive.GetSteering().linear; base.Update(); }
// Hand off the center to arrive behavior public SteeringOutput GetSteering(float maxSpeed) { Vector3 theCenter = CenterOfMass(); return(arrive.GetSteering(theCenter, maxSpeed)); }
void Update() { SteeringOutput movementSteering; //SteeringOutput lookSteering; //Update position and rotation transform.position += linearVelocity * Time.deltaTime; Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0); transform.eulerAngles += angularIncrement; switch (moveType) { case SteeringType.Pursue: movementSteering = pursueAI.GetSteering(); break; case SteeringType.Evade: movementSteering = evadeAI.GetSteering(); break; case SteeringType.FollowPath: movementSteering = followAI.GetSteering(); break; case SteeringType.Seek: movementSteering = seekAI.GetSteering(); break; case SteeringType.Flee: movementSteering = fleeAI.GetSteering(); break; case SteeringType.Seperation: movementSteering = seperationAI.GetSteering(); break; case SteeringType.Arrive: movementSteering = arriveAI.GetSteering(); break; case SteeringType.CollisionAvoidance: movementSteering = avoidAI.GetSteering(); break; case SteeringType.ObstacleAvoidance: movementSteering = obstacleAI.GetSteering(); break; default: movementSteering = new SteeringOutput(); break; } if (movementSteering != null) { linearVelocity += movementSteering.linear * Time.deltaTime; //angularVelocity += movementSteering.angular * Time.deltaTime; } switch (lookType) { case LookType.None: break; case LookType.Align: lookSteering = alignAI.GetSteering(); break; case LookType.Face: lookSteering = faceAI.GetSteering(); break; case LookType.LookWhereGoing: lookSteering = lookAI.GetSteering(); break; default: lookSteering = alignAI.GetSteering(); break; } if (lookSteering != null) { angularVelocity += lookSteering.angular * Time.deltaTime; } //Update kinematic reference with complex data it can't get by itself kinematic.GetData(movementSteering); kinematic.GetData(lookSteering); }
public override Steering GetSteering() { return(Arrive.GetSteering(target.position, npc, npc.exteriorRadius, maxAccel)); }