public IEnumerable <Status> TeleportFunction() { GameComponent closestItem = Creature.AI.Blackboard.GetData <GameComponent>(ObjectBlackboardName); if (closestItem != null) { var location = TeleportOffset + closestItem.BoundingBox.Center(); if (CheckForOcclusion) { VoxelHandle voxAt = new VoxelHandle(Agent.World.ChunkManager, GlobalVoxelCoordinate.FromVector3(location)); bool gotLocation = false; if (!voxAt.IsValid || !voxAt.IsEmpty) { // If we can't go to the preferred location, just try any free neighbor. voxAt = new VoxelHandle(Agent.World.ChunkManager, GlobalVoxelCoordinate.FromVector3(closestItem.BoundingBox.Center())); foreach (var neighbor in VoxelHelpers.EnumerateManhattanNeighbors2D(voxAt.Coordinate)) { VoxelHandle newVox = new VoxelHandle(Agent.World.ChunkManager, neighbor); if (newVox.IsValid && newVox.IsEmpty) { location = newVox.WorldPosition + new Vector3(0.5f, Agent.Physics.BoundingBox.Extents().Y, 0.5f); gotLocation = true; break; } } // If there's no free neighbor, just teleport directly to the object. if (!gotLocation) { location = closestItem.BoundingBox.Center(); } } } TeleportAct act = new TeleportAct(Creature.AI) { Location = location }; act.Initialize(); foreach (Act.Status status in act.Run()) { yield return(status); } } yield return(Status.Fail); }
public IEnumerable <Status> TeleportFunction() { Body closestItem = Creature.AI.Blackboard.GetData <Body>(ObjectName); if (closestItem != null) { TeleportAct act = new TeleportAct(Creature.AI) { Location = TeleportOffset + closestItem.BoundingBox.Center() }; act.Initialize(); foreach (Act.Status status in act.Run()) { yield return(status); } } yield return(Status.Fail); }
public IEnumerable<Status> TeleportFunction() { Body closestItem = Creature.AI.Blackboard.GetData<Body>(ObjectName); if (closestItem != null) { TeleportAct act = new TeleportAct(Creature.AI) { Location = TeleportOffset + closestItem.BoundingBox.Center() }; act.Initialize(); foreach (Act.Status status in act.Run()) { yield return status; } } yield return Status.Fail; }