/// <summary> /// This algorithm does a precise smooth of the path, making it as good as it can get, /// but using CPU more intesively /// </summary> /// <param name="entity">The entity that´s going to move through the path</param> /// <param name="path">The path the algorithm is going to try to smooth</param> /// <remarks> /// The check done for the edge information can fail sometimes, it depends on the map type. /// In complex maps a more carefully check should be done to see if the entity can reach the next edge /// end-point without changing its movement behavior (traversing the same terrain type) /// </remarks> public static void PathSmoothPrecise(MovingEntity entity, List <NavigationEdge> path) { int i, j; i = 0; //This method does the smoothing check between all pairs of nodes trying to see if edges can be removed from the path while (i < path.Count) { j = i + 1; while (j < path.Count) { if (entity.CanMoveBetween(path[i].Start, path[j].End) && path[i].Information == path[j].Information) { path[i].End = path[j].End; path.RemoveRange(i, j - i); i = j; i--; } else { j++; } } i++; } }
public WanderAI(MovingEntity movingEntity, WorldPosition blockStartPosition, int blockRadius) : base(movingEntity) { BlockRadius = blockRadius; BlockStartPosition = blockStartPosition; behaviorTree = createBehaviorTree(); }
protected virtual void SetPosition(MovingEntity entity) { GridSlot slot = LegacyLogic.Instance.MapLoader.Grid.GetSlot(entity.Position); transform.localPosition = Helper.SlotLocalPosition(slot.Position, slot.Height); transform.localRotation = Helper.GridDirectionToQuaternion(entity.Direction); }
public CollisionAvoidanceBehaviour(MovingEntity me, float MaxLookRadius, List <StaticEntity> objects, float MaxForce) : base(me) { MAX_SEE_AHEAD = MaxLookRadius; this.objects = objects; MAX_AVOID_FORCE = MaxForce; pos = me.Pos; }
public static Vector2D Cohesion(MovingEntity entity, List <MovingEntity> neighbours) { Vector2D centerOfMass = new Vector2D(0, 0); Vector2D steeringForce = new Vector2D(0, 0); int neighbourCount = 0; foreach (MovingEntity neighbour in neighbours) { if (neighbour.Tag == false) { continue; } centerOfMass.Add(neighbour.Pos); neighbourCount++; } if (neighbourCount > 0) { centerOfMass.Divide(neighbourCount); steeringForce = Seek(entity, centerOfMass); } return(steeringForce); }
public SteeringData CalculateData(MovingEntity entity, double deltaTimeS) { // Console.WriteLine(WanderTarget); // Randomize. WanderTarget += new Vector2( RandomClamped() * WanderJitter * deltaTimeS, RandomClamped() * WanderJitter * deltaTimeS); WanderTarget = WanderTarget.Normalize(); WanderTarget *= WanderRadius; Vector2 targetLocal = WanderTarget + entity.Heading * WanderDistance; // targetLocal -= entity.Position; return(new WanderSteeringData { DeltaVelocity = targetLocal, Entity = entity, WanderTarget = WanderTarget, WanderRadius = WanderRadius, WanderDistance = WanderDistance, WanderJitter = WanderJitter }); }
// to do public WanderingBehaviour(MovingEntity me) : base(me) { this.WanderJitter = 5; this.WanderRadius = 3; this.WanderDistance = 8; this.WanderTarget = me.Pos.Clone(); }
public Goal(MovingEntity owner, GoalType type, string name) { Status = Status.Inactive; Owner = owner; Type = type; Name = name; }
public void setNextPursuitTarget() { MovingEntity objSharkie = getVehicleByID(m_intSharkieID); objSharkie.Steering().ArriveOff(); objSharkie.Steering().FollowPathOff(); if (m_Vehicles.Count > 1) { bool blnSearch = true; while (blnSearch) { int tempNum = Utils.RandInt(0, (m_Vehicles.Count - 1)); if (m_Vehicles[tempNum].ID() != m_intSharkieID) { m_intVictimID = m_Vehicles[tempNum].ID(); blnSearch = false; } } MovingEntity objVictim = getVehicleByID(m_intVictimID); objSharkie.Steering().PursuitOn(objVictim); } }
//Pursui public Vector2 Pursuit(MovingEntity evader) { //if the evader is ahead and facing the agent then we can just seek //for the evader's current position. Vector2 ToEvader = evader.Position - _actor.Position; var relativeHeading = Vector2.Dot(evader.Heading, _actor.Heading); if ((Vector2.Dot(ToEvader, _actor.Heading) > 0) && (relativeHeading < -0.95)) //acos(0.95)=18 degs { return(Seek(evader.Position)); } //Not considered ahead so we predict where the evader will be. //the look-ahead time is proportional to the distance between the evader //and the pursuer; and is inversely proportional to the sum of the //agents' velocities var lookAheadTime = ToEvader.Length() / (_actor.MaxSpeed + evader.MaxSpeed); //todo:provjera lookAheadTime += TurnAroundTime(_actor, evader.Position); //todo:provjera //now seek to the predicted future position of the evader return(Seek(evader.Position + evader.Velocity * lookAheadTime)); }
bool AccumulateForce(MovingEntity vehicle, ref Vector2 runningTotal, Vector2 forceToAdd) { // print ("runningTotal: " + runningTotal + " . forceToAdd: " + forceToAdd); float magnitudeSoFar = runningTotal.magnitude; // how much steering force has been used? float magnitudeRemaining = (float)1.0f - magnitudeSoFar; // print ("magnitudeSoFar: " + magnitudeSoFar + " . magnitudeRemaining: " + magnitudeRemaining); if (magnitudeRemaining <= 0.0001f) { return(false); } float magnitudeToAdd = forceToAdd.magnitude; if (magnitudeToAdd < magnitudeRemaining) { runningTotal += forceToAdd; } else { runningTotal += forceToAdd.normalized * magnitudeRemaining; } return(true); }
// After all objects are initialized, Awake is called when the script // is being loaded. This occurs before any Start calls. // Use Awake instead of the constructor for initialization. public void Awake() { steerings = GetComponents <Steering>(); if (steerings == null || steerings.Length == 0) { Debug.Log("No Steering Behaviours"); } motor = GetComponent <Motor>(); if (motor == null) { Debug.Log("No Motor"); } movingEntity = GetComponent <MovingEntity>(); // optional aiController = GetComponent <AiController>(); // optional GameObject mainCamera = GameObject.Find("Main Camera"); if (mainCamera != null) { targetedCameras = mainCamera.GetComponents <TargetedCamera>(); } targetRowsPerColumn = Mathf.Max(3, targetRowsPerColumn); behaviourRowsPerColumn = Mathf.Max(1, behaviourRowsPerColumn); }
public Slash(MovingEntity origin, Vector2 target, float damage, bool flipped, Vector2?relativeOriginPosition = null) : base(origin.Position, origin) { Vector2 _relativeOriginPosition = relativeOriginPosition ?? Vector2.Zero; Vector2 newPosition = Vector2.Add(origin.Position.ToVector(), _relativeOriginPosition); Vector2 direction = new Vector2(target.X - newPosition.X, target.Y - newPosition.Y); direction.Normalize(); // Get Hitted Targets hitboxCircle = new Circle((int)(newPosition.X + direction.X * 40), (int)(newPosition.Y + direction.Y * 40), 16); newPosition.X += (direction.X * WorldGrid.BlockSize.X * 1.5f); newPosition.Y += (direction.Y * WorldGrid.BlockSize.Y * 1.5f); Angle = GeometryUtils.GetAngleFromDirection(direction) + (float)Math.PI * 0.5f; Flipped = flipped; origin.CanWalk = false; updatePosition(new WorldPosition(newPosition, origin.InteriorID)); List <LivingEntity> hittedObjects = CollisionUtils.GetLivingHittedObjects(hitboxCircle, origin.InteriorID, origin); foreach (var hittedObject in hittedObjects) { if (hittedObject is LivingEntity) { ((LivingEntity)hittedObject).ModifyHealth((int)-damage, Origin); } } }
public override void Act(StateController controller) { entity = controller.entity as MovingEntity; HashSet <TileProperties> visited = new HashSet <TileProperties>(); visited.Add(entity.Tile); Queue <TileProperties> fringes = new Queue <TileProperties>(); fringes.Enqueue(entity.Tile); while (fringes.Count > 0) { TileProperties previousTile = fringes.Dequeue(); TileProperties[] neighbors = previousTile.GetNeighbors(); for (int j = 0; j < neighbors.Length; j++) { TileProperties neighbor = neighbors[j]; if (neighbor && neighbor.Tile && !visited.Contains(neighbor)) { if (terrains.Contains(neighbor.Tile.terrainType)) { TryMoveToBiome(neighbor); return; } else { fringes.Enqueue(neighbor); } visited.Add(neighbor); } } } }
protected SteeringBehaviour(MovingEntity movingEntity, MovingEntity target, float weight) { Weight = weight; MovingEntity = movingEntity; Target = target; }
public override Vector2 CalculateSteering(MovingEntity vehicle) { Vector2 steeringForce = new Vector2(); if (seek) { steeringForce += SteeringBehaviors.Seek(vehicle); } if (flee) { steeringForce += SteeringBehaviors.Flee(vehicle); } if (arrive) { steeringForce += SteeringBehaviors.Arrive(vehicle, SteeringBehaviors.Deceleration.normal); } if (separation) { steeringForce += SteeringBehaviors.Separation(vehicle) * 3; } if (pursuit) { steeringForce += SteeringBehaviors.Pursuit(vehicle); } return(steeringForce); }
public override void Activate(MovingEntity user, Vector2Int direction = default) { this.direction = direction; Debug.Log("You aimed and did a theurgy thing!"); usagesLeft--; }
public FollowPathBehaviour(MovingEntity movingEntity, List <NavGraphNode> route) : base(movingEntity) { _route = route; _routeIndex = 0; _finished = false; _nextLocation = _route[_routeIndex].Position; }
public override void GetMoveVectors(Vector3 upVector, out Vector3 forward, out Vector3 right) { Transform importantT = myCamera.transform; if (pc.gravityApplication != MovingEntity.GravityState.none) { Vector3 generalDir = importantT.forward; if (importantT.forward == upVector) { generalDir = -importantT.up; } else if (importantT.forward == -upVector) { generalDir = importantT.up; } MovingEntity.CalculatePlanarMoveVectors(generalDir, upVector, out forward, out right); if (currentPitch > 90) { right *= -1; forward *= -1; } // if we're upside-down, flip to keep it consistent } else { right = importantT.right; forward = importantT.forward; } }
public static Vector2 Flee(MovingEntity vehicle, MovingEntity target) { //flee = true; // NEEDS ATTENTION //targetVehicle = target; Vector2 desiredVelocity = (vehicle.position - target.position).normalized * vehicle.maxSpeed; return (desiredVelocity - vehicle.velocity); }
public void EnforceNonPenetrationConstraint(MovingEntity centralEntity) { if (centralEntity.GetType() == typeof(Survivor)) { return; } foreach (MovingEntity entity in movingEntities) { if (entity.GetType() == typeof(Survivor)) { continue; } //make sure we don't check against the individual if (entity == centralEntity) { continue; } // calculate the distance between the positions of the entities Vector2 ToEntity = Vector2.Subtract(centralEntity.Pos, entity.Pos); float distFromEachOther = ToEntity.Length(); //if this distance is smaller than the sum of their radii then this entity must be moved away in the direction parallel to the ToEntity vector float amountOfOverlap = 10 + 10 - distFromEachOther; //move the entity a distance away equivalent to the amount of overlap if (amountOfOverlap >= 0) { centralEntity.Pos += Vector2.Multiply(Vector2.Divide(ToEntity, distFromEachOther), amountOfOverlap); } } }
public override Vector2 CalculateSteering(MovingEntity vehicle) { Vector2 steeringForce = Vector2.zero; Vector2 force; if (separation) { force = SteeringBehaviors.Separation(vehicle) * 1.0f; if (AccumulateForce(vehicle, ref steeringForce, force) && force != Vector2.zero) return steeringForce; } if (seek) { force = SteeringBehaviors.Seek(vehicle) * 1.0f; if (AccumulateForce(vehicle, ref steeringForce, force)) return steeringForce; } if (flee) { force = SteeringBehaviors.Flee(vehicle) * 1.0f; if (AccumulateForce(vehicle, ref steeringForce, force)) return steeringForce; } if (arrive) { force = SteeringBehaviors.Arrive(vehicle) * 1.0f; if (AccumulateForce(vehicle, ref steeringForce, force)) return steeringForce; } if (pursuit) { force = SteeringBehaviors.Pursuit(vehicle) * 1.0f; if (AccumulateForce(vehicle, ref steeringForce, force)) return steeringForce; } return steeringForce; }
public SteeringData CalculateData(MovingEntity entity, double deltaTimeS) { var centerOfMass = new Vector2(); int handledNeighborCount = 0; foreach (MovingEntity neighbor in Neighbors) { if (neighbor == entity) { continue; } centerOfMass += neighbor.Position; handledNeighborCount++; } if (handledNeighborCount > 0) { centerOfMass /= handledNeighborCount; } CohesionSteeringData data = (CohesionSteeringData) new SeekSteeringBehavior { Target = centerOfMass } .CalculateData(entity, new CohesionSteeringData()); data.CenterOfMass = centerOfMass; return(data); }
private void RenderVehicle(MovingEntity objVehicle, Graphics objGraphics, Pen objPen) { PointF pntLeft, pntFront, pntRight; if (UseSmoothing) { Vector2D SmoothedPerp = objVehicle.SmoothedHeading().Perp(); pntLeft = (PointF)(objVehicle.Pos + (SmoothedPerp * objVehicle.BRadius)); pntFront = (PointF)(objVehicle.Pos + (objVehicle.SmoothedHeading() * (objVehicle.BRadius * 2))); pntRight = (PointF)(objVehicle.Pos - (SmoothedPerp * objVehicle.BRadius)); } else { pntLeft = (PointF)(objVehicle.Pos + (objVehicle.Side() * objVehicle.BRadius)); pntFront = (PointF)(objVehicle.Pos + (objVehicle.Heading() * (objVehicle.BRadius * 2))); pntRight = (PointF)(objVehicle.Pos - (objVehicle.Side() * objVehicle.BRadius)); } PointF[] points = new PointF[4]; points[0] = pntLeft; points[1] = pntFront; points[2] = pntRight; points[3] = pntLeft; objGraphics.DrawPolygon(objPen, points); }
public static Vector2 Seek(MovingEntity vehicle, Vector2 targetPosition) { // Debug.Log("vehicle position = " + vehicle.position + " - targetPos = " + targetPosition); Vector2 desiredVelocity = (targetPosition - vehicle.position).normalized * vehicle.maxSpeed; return(desiredVelocity - vehicle.velocity); }
public static Vector2 Arrive(MovingEntity vehicle, Deceleration deceleration) { //arrive = true; // NEEDS ATTENTION float distance = Vector2.Distance(vehicle.targetPos, vehicle.position); // savedDeceleration = (double)deceleration; if (distance < 0.001) { return(Vector2.zero); } else if (distance > 0) { double decelerationTweaker = 0.2; double speed = distance / ((double)deceleration * decelerationTweaker); speed = Mathf.Min((float)speed, vehicle.maxSpeed); // don't exceed max speed Vector2 desiredVelocity = (vehicle.targetPos - vehicle.position) * (float)speed / distance; return(desiredVelocity - vehicle.velocity); } return(Vector2.zero); }
public GuardAI(MovingEntity movingEntity, WorldPosition blockGuardPosition, Vector2 lookDirection) : base(movingEntity) { BlockGuardPosition = blockGuardPosition; LookDirection = lookDirection; behaviorTree = createBehaviorTree(); }
private String GetFoodStepAudioID() { MovingEntity movingEntity = (MovingEntity)MyController; Grid grid = LegacyLogic.Instance.MapLoader.Grid; GridSlot slot = grid.GetSlot(movingEntity.Position); String text = null; ETerrainType terrainType = slot.TerrainType; if ((terrainType & ETerrainType.WATER) > ETerrainType.NONE) { text = m_foodstepSoundWater; } else if ((terrainType & ETerrainType.ROUGH) > ETerrainType.NONE) { text = m_foodstepSoundRough; } else if ((terrainType & ETerrainType.FOREST) > ETerrainType.NONE) { text = m_foodstepSoundForest; } else if ((terrainType & ETerrainType.LAVA) > ETerrainType.NONE) { text = m_foodstepSoundLava; } if (String.IsNullOrEmpty(text)) { text = "Move_Party"; } return(text); }
public Vector2 GetRandomEntityPosition() { int attempts = 0; var position = new Vector2(); while (attempts < 1000) // shouldn't hardcode max attempts { position.x = Random.Range( World.Instance.Center.x - World.Instance.Size.x / 2, World.Instance.Center.x + World.Instance.Size.x / 2); position.y = Random.Range( World.Instance.Center.y - World.Instance.Size.y / 2, World.Instance.Center.y + World.Instance.Size.y / 2); if (!MovingEntity.IsEntityInObstacle(position) && GetClosestNodeToPosition(position) != NO_CLOSEST_NODE_FOUND) { return(position); } attempts++; } // give up. just return a random node position return(Graph.GetRandomNodePosition()); }
public SteeringData CalculateData(MovingEntity entity, double deltaTimeS) { var averageHeading = new Vector2(); int handledNeighborCount = 0; foreach (MovingEntity neighbor in Neighbors) { if (neighbor == entity) { continue; } averageHeading += neighbor.Heading; handledNeighborCount++; } if (handledNeighborCount > 0) { averageHeading /= handledNeighborCount; averageHeading -= entity.Heading; } return(new AllignSteeringData { DeltaVelocity = averageHeading, Entity = entity, AverageHeading = averageHeading }); }
protected virtual void Awake() { movingObject = gameObject; movingEntity = GetComponent <MovingEntity>(); motor = GetComponent <Motor>(); tickManager = new TickManager(); }
public FlockingBehaviour(MovingEntity movingEntity) : base(movingEntity) { maxSteeringForce = 5; separationAmount = 100; cohesionAmount = 2; alignmentAmount = 1; }
/// <summary> /// Creates a new ant entity. /// </summary> /// <param name="contentProvider"> /// The content provider. /// </param> /// <param name="position"> /// The position. /// </param> /// <returns> /// A new ant entity. /// </returns> public static GameEntityBase Create(ContentProvider contentProvider, Point position) { var animation = new Texture2D[2]; animation[0] = contentProvider.GetSpriteTexture(SpriteResource.YellowAntWalk1); animation[1] = contentProvider.GetSpriteTexture(SpriteResource.YellowAntWalk2); // apply interactive elements first var baseEntity = new GameEntityBase(EntityType.Ant, new Rectangle(position.X, position.Y, 1, 1), Player.Black); baseEntity = new MovingEntity(baseEntity); baseEntity = new AnimationRenderEntity(baseEntity, animation); baseEntity = new CollisionBarrierEntity(baseEntity); return new WorkerAntIntelligence(baseEntity); }
public static Vector2 Pursuit(MovingEntity vehicle, MovingEntity target) { //pursuit = true; // NEEDS ATTENTION //targetVehicle = target; Vector2 toTarget = target.position - vehicle.position; float relativeHeading = Vector2.Dot (vehicle.heading, target.heading); if ((Vector2.Dot (toTarget, vehicle.heading) > 0) && (relativeHeading < -0.95)) return Seek (vehicle, target.position); // now time to predict float lookAheadTime = toTarget.magnitude / (vehicle.maxSpeed + target.velocity.magnitude); return Seek (vehicle, target.position + target.velocity * lookAheadTime); }
public override Vector2 CalculateSteering(MovingEntity vehicle) { Vector2 steeringForce = new Vector2(); if (seek) steeringForce += SteeringBehaviors.Seek(vehicle); if (flee) steeringForce += SteeringBehaviors.Flee(vehicle); if (arrive) steeringForce += SteeringBehaviors.Arrive(vehicle, SteeringBehaviors.Deceleration.normal); if (separation) steeringForce += SteeringBehaviors.Separation(vehicle) * 3; if (pursuit) steeringForce += SteeringBehaviors.Pursuit(vehicle); return steeringForce; }
bool AccumulateForce(MovingEntity vehicle, ref Vector2 runningTotal, Vector2 forceToAdd) { // print ("runningTotal: " + runningTotal + " . forceToAdd: " + forceToAdd); float magnitudeSoFar = runningTotal.magnitude; // how much steering force has been used? float magnitudeRemaining = (float)1.0f - magnitudeSoFar; // print ("magnitudeSoFar: " + magnitudeSoFar + " . magnitudeRemaining: " + magnitudeRemaining); if (magnitudeRemaining <= 0.0001f) return false; float magnitudeToAdd = forceToAdd.magnitude; if (magnitudeToAdd < magnitudeRemaining) runningTotal += forceToAdd; else runningTotal += forceToAdd.normalized * magnitudeRemaining; return true; }
public static Vector2 Arrive(MovingEntity vehicle, Deceleration deceleration) { //arrive = true; // NEEDS ATTENTION float distance = Vector2.Distance(vehicle.targetPos, vehicle.position); // savedDeceleration = (double)deceleration; if (distance < 0.001) return Vector2.zero; else if (distance > 0) { double decelerationTweaker = 0.2; double speed = distance / ((double)deceleration * decelerationTweaker); speed = Mathf.Min((float)speed, vehicle.maxSpeed); // don't exceed max speed Vector2 desiredVelocity = (vehicle.targetPos - vehicle.position) * (float)speed / distance; return (desiredVelocity - vehicle.velocity); } return Vector2.zero; }
public void Awake() { TraversalMargin = 3; movingEntity = GetComponent<MovingEntity>(); aiController = GetComponent<AiController>(); seek = GetComponent<Seek>(); arrive = GetComponent<Arrive>(); }
public Explore(MovingEntity owner) : base(owner, Goal_Type.Explore) { this.destinationIsSet = false; }
public FindWater(MovingEntity owner) : base(owner, Goal_Type.FindFood) { this.waterSource = typeof(Entities.Static_Objects.WaterEntity); }
public FollowPath(MovingEntity owner, List<Vector2D> path) : base(owner, Goal_Type.FollowPath) { this.path = path; }
public void Flee(MovingEntity vehicle) { DefaultBehavior(); movingEntity.targetVehicle = vehicle; steeringCalculate.flee = true; }
// This creates the GUI inside the window. // It requires the id of the window it's currently making GUI for. private void WindowFunction(int windowID) { // Draw any Controls inside the window here. if (steerings == null || steerings.Length == 0) { Debug.Log("Getting Steering Behaviours"); steerings = GetComponents<Steering>(); } if (steerings == null || steerings.Length == 0) { Debug.Log("No Steering Behaviours"); } if (motor == null) { Debug.Log("Getting Motor"); motor = GetComponent<Motor>(); } if (motor == null) { Debug.Log("No Motor"); return; } if (movingEntity == null) { movingEntity = GetComponent<MovingEntity>(); // optional } if (aiController == null) { aiController = GetComponent<AiController>(); // optional } if (aiController != null) { if (movingEntity != null && movingEntity.enabled) { aiController.SetSteering(null); } else { aiController.SetSteering(activeSteering); } } if (centeredLabelStyle == null) { centeredLabelStyle = new GUIStyle(GUI.skin.GetStyle("Label")); centeredLabelStyle.alignment = TextAnchor.MiddleCenter; } GUILayout.BeginHorizontal(); GUILayout.Label(name, centeredLabelStyle); if (GUILayout.Button(motor.isAiControlled ? "is an AI" : "is a Player")) { motor.isAiControlled = !motor.isAiControlled; } if (targetedCameras != null && GUILayout.Button("Watch")) { foreach (TargetedCamera targetedCamera in targetedCameras) { targetedCamera.target = transform; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); int behaviourIndex = 0; while (behaviourIndex < steerings.Length) { GUILayout.BeginVertical(); int behaviourRow = 0; while (behaviourRow < behaviourRowsPerColumn && behaviourIndex < steerings.Length) { if (GUILayout.Button(steerings[behaviourIndex].GetType().Name)) { foreach (Steering steering in steerings) { if (steering != steerings[behaviourIndex]) { steering.enabled = steering.isOn = false; } } steerings[behaviourIndex].enabled = steerings[behaviourIndex].isOn = true; activeSteering = steerings[behaviourIndex]; if (aiController != null) { if (movingEntity != null && movingEntity.enabled) { aiController.SetSteering(null); } else { aiController.SetSteering(activeSteering); } } } behaviourRow++; behaviourIndex++; } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); int targetRow; int targetIndex = 0; GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); if (GUILayout.Button("None") && activeSteering != null) { activeSteering.targetObject = null; activeSteering.targetPosition = transform.position; } if (GUILayout.Button("Origin") && activeSteering != null) { activeSteering.targetObject = null; activeSteering.targetPosition = Vector3.zero; } if (GUILayout.Button("Random") && activeSteering != null) { activeSteering.targetObject = null; activeSteering.targetPosition = Random.insideUnitSphere * 50; } targetRow = 3; while (targetRow < targetRowsPerColumn && targetIndex < targets.Length) { if (GUILayout.Button(targets[targetIndex].name) && activeSteering != null) { activeSteering.targetObject = targets[targetIndex]; } targetRow++; targetIndex++; } GUILayout.EndVertical(); while (targetIndex < targets.Length) { GUILayout.BeginVertical(); targetRow = 0; while (targetRow < targetRowsPerColumn && targetIndex < targets.Length) { if (GUILayout.Button(targets[targetIndex].name) && activeSteering != null) { activeSteering.targetObject = targets[targetIndex]; } targetRow++; targetIndex++; } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); // Make the windows be draggable. GUI.DragWindow(); }
public Think(MovingEntity owner) : base(owner, Goal_Type.Think) { subGoals = new Stack<Goal>(); }
// Use this for initialization void Start() { entity = transform.GetComponent<MovingEntity>(); }
public MoveToMouseClick(MovingEntity owner, Vector2D mouseLocation) : base(owner, Goal_Type.MoveToMousClick) { this.mouseLocation = mouseLocation; }
public Think(MovingEntity owner) : base(owner, Goal_Type.Think) { }
public Arrive(MovingEntity owner, MovingEntity target) : base(owner, Goal_Type.Arrive) { this.target = target; }
//public enum behaviors { seek = false, flee = false, arrive = false, separation = false, pursuit = false; }; public virtual Vector2 CalculateSteering(MovingEntity vehicle) { Debug.Log("ERROR!"); return new Vector2(0, 0); }
// After all objects are initialized, Awake is called when the script // is being loaded. This occurs before any Start calls. // Use Awake instead of the constructor for initialization. public void Awake() { steerings = GetComponents<Steering>(); if (steerings == null || steerings.Length == 0) { Debug.Log("No Steering Behaviours"); } motor = GetComponent<Motor>(); if (motor == null) { Debug.Log("No Motor"); } movingEntity = GetComponent<MovingEntity>(); // optional aiController = GetComponent<AiController>(); // optional GameObject mainCamera = GameObject.Find("Main Camera"); if (mainCamera != null) { targetedCameras = mainCamera.GetComponents<TargetedCamera>(); } targetRowsPerColumn = Mathf.Max(3, targetRowsPerColumn); behaviourRowsPerColumn = Mathf.Max(1, behaviourRowsPerColumn); }
public Vector2 GetRandomEntityPosition(MovingEntity movingEntity) { int attempts = 0; var position = new Vector2(); while (attempts < 1000) // shouldn't hardcode max attempts { position.x = Random.Range(Center.x - Size.x / 2, Center.x + Size.x / 2); position.y = Random.Range(Center.y - Size.y / 2, Center.y + Size.y / 2); if (!movingEntity.IsEntityInObstacle(position)) { return position; } attempts++; } // give up. just return a random node position return position; }
public FindFood(MovingEntity owner) : base(owner, Goal_Type.FindFood) { }
public SteeringPerson(MovingEntity me, SteeringCalculate sc) : base(me, sc) { // don't need anything here }
public MoveToEntity(MovingEntity owner, Type target) : base(owner, Goal_Type.MoveToEntity) { this.targetType = target; }
public SearchContacts(MovingEntity owner) : base(owner, Goal_Type.SearchContacts) { }
public Wander(MovingEntity owner) : base(owner, Goal_Type.Wander) { }
public CompositeGoal(MovingEntity owner, Goal_Type type) : base(owner, type) { }
public Arrive(MovingEntity owner, Vector2D pos) : base(owner, Goal_Type.Arrive) { this.target = pos; }
public Goal(MovingEntity owner, Goal_Type type) { this.Owner = owner; this.Type = type; this.Status = Goal_Status.INACTIVE; }
public FindFood(MovingEntity owner, Type target) : base(owner, Goal_Type.FindFood) { this.foodSource = target; }