public Decomposer(SteeringPipeline pipeline, NavMeshPathGraph navMesh, DynamicCharacter character) { Character = character; Pipeline = pipeline; aStarPathFinding = new NodeArrayAStarPathFinding(navMesh, new EuclideanDistanceHeuristic()); aStarPathFinding.NodesPerSearch = 150; }
// Use this for initialization void Awake() { this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.character = new DynamicCharacter(this.characterAvatar); this.enemies = new List <DynamicCharacter>(); for (int i = 0; i < enemiesAvatar.Length; i++) { DynamicCharacter enemy = new DynamicCharacter(this.enemiesAvatar[i]); DynamicBackAndForth movement = new DynamicBackAndForth() { Character = enemy.KinematicData, MaxAcceleration = 10.0f, StopRadius = 2.0f, SlowRadius = 5.0f, MoveDistance = 25.0f }; movement.CalculatePositions(); enemy.Movement = movement; this.enemies.Add(enemy); } this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; }
public GoalBounding(NavMeshPathGraph navMesh, BoundingBox mapSize) { //Hack to access private field with all the nodes of the mesh List<NavigationGraphNode> nodeList = (List<NavigationGraphNode>)Utils.Reflection.GetInstanceField( typeof(RAINNavigationGraph), navMesh, "_pathNodes"); nodeInfos = new NodeRecordArray(nodeList, mapSize); }
public List <Vector3> SmoothPath(List <Vector3> pathPositions, NavMeshPathGraph _navMesh, int _mode) { mode = _mode; if (mode < 0 || mode > 2) { mode = 1; } if (mode == 1) { ray = new Ray(); hit = new RaycastHit(); } navMesh = _navMesh; smoothedPositions.Clear(); count = pathPositions.Count; lastAdded = pathPositions.First(); smoothedPositions.Add(lastAdded); for (int i = 0; i < count - 2; i++) { if (!CanBeDeleted(lastAdded, pathPositions[i + 2])) { smoothedPositions.Add(pathPositions[i + 1]); lastAdded = pathPositions[i + 1]; } } smoothedPositions.Add(pathPositions.Last()); return(smoothedPositions); }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding pathfindingAlgorithm) { this.draw = true; this.navMesh = navMeshGraph; this.AStarPathFinding = pathfindingAlgorithm; this.AStarPathFinding.NodesPerSearch = 100; }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding pathfindingAlgorithm) { this.MCTSActive = true; //change this if you want to try DL-GOAP this.draw = false; this.navMesh = navMeshGraph; this.AStarPathFinding = pathfindingAlgorithm; this.AStarPathFinding.NodesPerSearch = 100; }
public NodeArrayAStarPathFinding(NavMeshPathGraph graph, IHeuristic heuristic) : base(graph, null, null, heuristic) { //do not change this var nodes = this.GetNodesHack(graph); this.NodeRecordArray = new NodeRecordArray(nodes); this.Open = this.NodeRecordArray; this.Closed = this.NodeRecordArray; }
// Use this for initialization void Start() { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.aStarPathFinding = new AStarPathfinding(this.navMesh, new SimpleUnorderedNodeList(), new SimpleUnorderedNodeList(), new ZeroHeuristic()); }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding pathfindingAlgorithm) { this.draw = false; this.navMesh = navMeshGraph; this.AStarPathFinding = pathfindingAlgorithm; this.AStarPathFinding.NodesPerFrame = 15; }
public AStarPathfinding(NavMeshPathGraph graph, IOpenSet open, IClosedSet closed, IHeuristic heuristic) { this.NavMeshGraph = graph; this.Open = open; this.Closed = closed; this.InProgress = false; this.Heuristic = heuristic; }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding pathfindingAlgorithm) { this.draw = true; this.navMesh = navMeshGraph; this.AStarPathFinding = pathfindingAlgorithm; this.AStarPathFinding.NodesPerFrame = 100; //it was NodesPerSearch before this.characterAnimator = this.GetComponentInChildren <Animator> (); }
public InfluenceMap(NavMeshPathGraph navMesh, IOpenLocationRecord open, IClosedLocationRecord closed, IInfluenceFunction influenceFunction, float influenceThreshold) { this.NavMeshGraph = navMesh; this.Open = open; this.Closed = closed; this.InfluenceFunction = influenceFunction; this.InfluenceThreshold = influenceThreshold; this.NodesPerFlood = 50; }
public AStarPathfinding(NavMeshPathGraph graph, IOpenSet open, IClosedSet closed, IHeuristic heuristic) { this.NavMeshGraph = graph; this.Open = open; this.Closed = closed; this.NodesPerFrame = uint.MaxValue; //by default we process all nodes in a single request this.InProgress = false; this.Heuristic = heuristic; }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding pathfindingAlgorithm) { this.draw = true; this.navMesh = navMeshGraph; this.AStarPathfinding = pathfindingAlgorithm; this.AStarPathfinding.NodeLimit = 100; this.characterAnimator = this.GetComponentInChildren <Animator> (); }
public AStarPathfinding(NavMeshPathGraph graph, IOpenSet open, IClosedSet closed, IHeuristic heuristic) { this.NavMeshGraph = graph; this.Open = open; this.Closed = closed; this.NodesPerSearch = uint.MaxValue; //by default we process all nodes in a single request this.InProgress = false; this.Heuristic = heuristic; }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathFinding pathFindingAlgorithm) { this.draw = true; this.navMesh = navMeshGraph; this.AStarPathFinding = pathFindingAlgorithm; this.AStarPathFinding.NodesPerSearch = 2000; this.actionsPerformed = 0; this.characterAnimator = this.GetComponentInChildren <Animator>(); }
private static void CalculateGoalBounds() { //get the NavMeshGraph from the current scene NavMeshPathGraph navMesh = GameObject.Find("Navigation Mesh").GetComponent <NavMeshRig>().NavMesh.Graph; //this is needed because RAIN AI does some initialization the first time the QuantizeToNode method is called //if this method is not called, the connections in the navigationgraph are not properly initialized navMesh.QuantizeToNode(new Vector3(0, 0, 0), 1.0f); var dijkstra = new GoalBoundsDijkstraMapFlooding(navMesh); GoalBoundingTable goalBoundingTable = new GoalBoundingTable(); var nodes = GetNodesHack(navMesh); goalBoundingTable.table = new NodeGoalBounds[nodes.Count]; NodeGoalBounds auxGoalBounds; //calculate goal bounds for each edge for (int i = 0; i < nodes.Count; i++) { if (nodes[i] is NavMeshEdge) { //initialize the GoalBounds structure for the edge auxGoalBounds = new NodeGoalBounds { connectionBounds = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds[nodes[i].OutEdgeCount] }; for (int j = 0; j < nodes[i].OutEdgeCount; j++) { auxGoalBounds.connectionBounds[j] = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds(); auxGoalBounds.connectionBounds[j].InitializeBounds(nodes[i].LocalPosition); } if (i % 10 == 0) { float percentage = (float)i / (float)nodes.Count; EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Calculating goal bounds for each edge", percentage); } //run a Dijkstra mapflooding for each node dijkstra.Search(nodes[i], auxGoalBounds); goalBoundingTable.table[i] = auxGoalBounds; } } //saving the table to a binary file EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Saving GoalBoundsTable to an Asset file", 100); goalBoundingTable.Save(Application.dataPath + "/Resources/", "GoalBoundingTable.dat"); //saving the assets, this takes forever using Unity's serialization mechanism EditorUtility.ClearProgressBar(); }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding AStarPathFinding) { this.MCTSActive = true; this.draw = true; this.navMesh = navMeshGraph; this.AStarPathFinding = AStarPathFinding; this.AStarPathFinding.NodesPerFrame = 100; this.characterAnimator = this.GetComponentInChildren <Animator> (); }
// Use this for initialization void Awake() { this.character = new DynamicCharacter(characterAvatar); var clusterGraph = Resources.Load <ClusterGraph>("ClusterGraph"); this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.AStarPathFinding = new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new GatewayHeuristic(clusterGraph)); this.AStarPathFinding.NodesPerSearch = 100; }
public GoalBoundsDijkstraMapFlooding(NavMeshPathGraph graph) { this.NavMeshGraph = graph; //do not change this var nodes = this.GetNodesHack(graph); this.NodeRecordArray = new NodeRecordArray(nodes); this.Open = this.NodeRecordArray; this.Closed = this.NodeRecordArray; }
// Use this for initialization void Awake() { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanHeuristic()); //this.aStarPathFinding = new AStarPathfinding(this.navMesh, new NodePriorityHeap(), new NodeHashmap(), new EuclideanHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; }
private List<NavigationGraphNode> GetNodesHack(NavMeshPathGraph graph) { //this hack is needed because in order to implement NodeArrayA* you need to have full acess to all the nodes in the navigation graph in the beginning of the search //unfortunately in RAINNavigationGraph class the field which contains the full List of Nodes is private //I cannot change the field to public, however there is a trick in C#. If you know the name of the field, you can access it using reflection (even if it is private) //using reflection is not very efficient, but it is ok because this is only called once in the creation of the class //by the way, NavMeshPathGraph is a derived class from RAINNavigationGraph class and the _pathNodes field is defined in the base class, //that's why we're using the type of the base class in the reflection call return (List<NavigationGraphNode>)Utils.Reflection.GetInstanceField(typeof(RAINNavigationGraph), graph, "_pathNodes"); }
public SecureNodeArrayAStarPathFinding(AutonomousCharacter character, NavMeshPathGraph graph, IHeuristic heuristic) : base(graph, null, null, heuristic) { //do not change this var nodes = this.GetNodesHack(graph); this.NodeRecordArray = new NodeRecordArray(nodes); this.Open = this.NodeRecordArray; this.Closed = this.NodeRecordArray; this.character = character; }
public void Initialize(NavMeshPathGraph navMeshGraph, AStarPathfinding pathfindingAlgorithm) { this.draw = false; this.navMesh = navMeshGraph; this.AStarPathFinding = pathfindingAlgorithm; this.AStarPathFinding.NodesPerFrame = 200; this.smoothedPath = new GlobalPath(); }
private static List <NavigationGraphNode> GetNodesHack(NavMeshPathGraph graph) { //this hack is needed because in order to implement NodeArrayA* you need to have full acess to all the nodes in the navigation graph in the beginning of the search //unfortunately in RAINNavigationGraph class the field which contains the full List of Nodes is private //I cannot change the field to public, however there is a trick in C#. If you know the name of the field, you can access it using reflection (even if it is private) //using reflection is not very efficient, but it is ok because this is only called once in the creation of the class //by the way, NavMeshPathGraph is a derived class from RAINNavigationGraph class and the _pathNodes field is defined in the base class, //that's why we're using the type of the base class in the reflection call return((List <NavigationGraphNode>)Assets.Scripts.IAJ.Unity.Utils.Reflection.GetInstanceField(typeof(RAINNavigationGraph), graph, "_pathNodes")); }
// Use this for initialization void Awake() { this.character = new DynamicCharacter(characterAvatar); var clusterGraph = Resources.Load <ClusterGraph>("ClusterGraph"); this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; //this.AStarPathFinding = new AStarPathfinding(this.navMesh, new NodePriorityHeap(), new NodeHashTable(), new EuclidianHeuristic()); //this.AStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclidianHeuristic()); this.AStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new GatewayHeuristic(clusterGraph)); this.AStarPathFinding.NodesPerSearch = 100; }
public static bool CheckifHit(Vector3 start, Vector3 end, NavMeshPathGraph navMesh) { float delta = 0.0f; for (delta = 0.02f; delta < 1; delta += 0.02f) { if (!navMesh.IsPointOnGraph(Vector3.Lerp(start, end, delta), 1)) { return(true); } } return(false); }
// Use this for initialization void Awake() { this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.character = new DynamicCharacter(this.characterAvatar) { Drag = DRAG, MaxSpeed = MAX_SPEED }; aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); aStarPathFinding.NodesPerSearch = 100; }
// Use this for initialization void Awake() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open("Assets/GoalBoundingData/GoalBounding.dat", FileMode.Open); GoalBoundingTable goalBoundingTable = (GoalBoundingTable)bf.Deserialize(file); file.Close(); this.currentClickNumber = 1; navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanHeuristic(), goalBoundingTable)); //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanHeuristic())); }
// Use this for initialization void Awake() { this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.character = new DynamicCharacter(this.characterAvatar) { Drag = DRAG, MaxSpeed = MAX_SPEED }; this.bots = GameObject.FindGameObjectsWithTag("Bot"); this.decomposer = new Decomposer(new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic())); this.decomposer.searchAlgorithm.NodesPerSearch = 100; }
// Use this for initialization void Awake () { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; BoundingBox mapSize = new BoundingBox(); mapSize.minX = -200; mapSize.minZ = -200; mapSize.maxX = 200; mapSize.maxZ = 200; this.goalbounding = new GoalBounding(navMesh, mapSize); this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh,new SimpleHeuristic(),true); this.aStarPathFinding.NodesPerSearch = 100; }
public NodeArrayAStarPathFinding(NavMeshPathGraph graph, IHeuristic heuristic, bool usingGoalBounding) : base(graph, null, null, heuristic) { //do not change this var nodes = this.GetNodesHack(graph); this.NodeRecordArray = new NodeRecordArray(nodes, new BoundingBox()); this.Open = this.NodeRecordArray; this.Closed = this.NodeRecordArray; this.UsingGoalBounding = usingGoalBounding; this.fileReader = new FileReader(); if (usingGoalBounding) { fileReader.fileName = "goalBoundingInfo.xml"; NodeRecordArray = fileReader.readFile(this.NodeRecordArray); } }
public List <Vector3> SmoothPath(List <Vector3> pathPositions, NavMeshPathGraph _navMesh, int _mode) { setMode(_mode); navMesh = _navMesh; smoothedPositions.Clear(); count = pathPositions.Count; lastAdded = pathPositions.First(); smoothedPositions.Add(lastAdded); for (int i = 0; i < count - 2; i++) { if (!CanBeDeleted(lastAdded, pathPositions[i + 2])) { smoothedPositions.Add(pathPositions[i + 1]); lastAdded = pathPositions[i + 1]; } } smoothedPositions.Add(pathPositions.Last()); return(smoothedPositions); }
// Use this for initialization private void Awake() { this.draw = true; NavMeshPathGraph navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.character = new DynamicCharacter(this.characterAvatar); this.Pedestrians = new List <GameObject>(GameObject.FindGameObjectsWithTag("Pedestrian")).ConvertAll(p => new Pedestrian(p)); // Targeter TargeterComponent = new Targeter(this); // Decomposer DecomposerComponent = new Decomposer(this, navMesh, this.character); // TargetCollisionConstraint PathConstraints = new List <IConstraint>(); PathConstraints.Add(new PedestrianAvoidanceConstraint(this, character, this.Pedestrians)); PathConstraints.Add(new AvoidObstacleConstraint(this.character)); // Movement Constraints MovementConstraints = new List <IConstraint>(); StaticObstacleConstraint obsConstraint = new StaticObstacleConstraint(character) { AvoidMargin = 10f }; MovementConstraints.Add(obsConstraint); if (CharacterInUse.Equals(CharacterType.Car)) { Actuator = new CarActuator(this.character); } else if (CharacterInUse.Equals(CharacterType.Human)) { Actuator = new HumanActuator(this.character); } }
public void Start() { this.draw = true; this.influenceMapDebugMode = 0; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); //initialization of the movement algorithms this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic(), this); this.aStarPathFinding.NodesPerSearch = 500; var steeringPipeline = new SteeringPipeline { MaxAcceleration = 40.0f, MaxConstraintSteps = 2, Character = this.Character.KinematicData, }; this.decomposer = new PathFindingDecomposer(steeringPipeline, this.aStarPathFinding); this.Targeter = new FixedTargeter(steeringPipeline); steeringPipeline.Targeters.Add(this.Targeter); steeringPipeline.Decomposers.Add(this.decomposer); steeringPipeline.Actuator = new FollowPathActuator(steeringPipeline); this.Character.Movement = steeringPipeline; //initialization of the Influence Maps this.RedInfluenceMap = new InfluenceMap(this.navMesh,new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); this.GreenInfluenceMap = new InfluenceMap(this.navMesh, new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); this.ResourceInfluenceMap = new InfluenceMap(this.navMesh, new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); this.CombinedInfluence = new Dictionary<LocationRecord, float>(); this.SecurityMap = new Dictionary<LocationRecord, float>(); //initialization of the GOB decision making //let's start by creating 5 main goals //the eat goal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.ConquerGoal = new Goal(CONQUER_GOAL, 1.5f) { InsistenceValue = 5.0f }; this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); this.Goals.Add(this.ConquerGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); this.Actions.Add(new PlaceFlag(this)); this.ActiveResources = new Dictionary<NavigationGraphNode, IInfluenceUnit>(); int boars = 0; int chests = 0; int trees = 0; int beds = 0; foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { chests++; this.Actions.Add(new PickUpChest(this, chest)); this.AddResource(new Resource(this.navMesh.QuantizeToNode(chest.transform.position, 1.0f))); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { trees++; this.Actions.Add(new GetArrows(this, tree)); this.AddResource(new Resource(this.navMesh.QuantizeToNode(tree.transform.position, 1.0f))); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { beds++; this.Actions.Add(new Sleep(this, bed)); this.AddResource(new Resource(this.navMesh.QuantizeToNode(bed.transform.position, 1.0f))); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { boars++; this.AddResource(new Resource(this.navMesh.QuantizeToNode(boar.transform.position, 1.0f))); this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } this.ResourceInfluenceMap.Initialize(this.ActiveResources.Values.ToList()); //flags used for the influence map this.RedFlags = new List<IInfluenceUnit>(); foreach (var redFlag in GameObject.FindGameObjectsWithTag("RedFlag")) { this.RedFlags.Add(new Flag(this.navMesh.QuantizeToNode(redFlag.transform.position, 1.0f), FlagColor.Red)); } this.GreenFlags = new List<IInfluenceUnit>(); foreach (var greenFlag in GameObject.FindGameObjectsWithTag("GreenFlag")) { this.GreenFlags.Add(new Flag(this.navMesh.QuantizeToNode(greenFlag.transform.position, 1.0f), FlagColor.Green)); } this.RedInfluenceMap.Initialize(this.RedFlags); this.GreenInfluenceMap.Initialize(this.GreenFlags); var worldModel = new CurrentStateWorldModelFEAR(this.GameManager, this.Actions, this.Goals); worldModel.InitArrays( boars, trees, beds, chests); this.GOAPDecisionMaking = new DepthLimitedGOAPDecisionMaking(worldModel,this.Actions,this.Goals); }
private static void CalculateGoalBounds() { Debug.Log("Creating goalbounds table"); DateTime startTime = DateTime.Now; //get the NavMeshGraph from the current scene NavMeshPathGraph navMesh = GameObject.Find("Navigation Mesh").GetComponent <NavMeshRig>().NavMesh.Graph; //this is needed because RAIN AI does some initialization the first time the QuantizeToNode method is called //if this method is not called, the connections in the navigationgraph are not properly initialized navMesh.QuantizeToNode(new Vector3(0, 0, 0), 1.0f); GoalBoundingTable goalBoundingTable = new GoalBoundingTable(); var nodes = GetNodesHack(navMesh); goalBoundingTable.table = new NodeGoalBounds[nodes.Count]; var dijkstra = new GoalBoundsDijkstraMapFlooding(nodes); NodeGoalBounds auxGoalBounds; //calculate goal bounds for each edge for (int i = 0; i < nodes.Count; i++) { if (nodes[i] is NavMeshEdge) { //initialize the GoalBounds structure for the edge auxGoalBounds = new NodeGoalBounds(); auxGoalBounds.connectionBounds = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds[nodes[i].OutEdgeCount]; for (int j = 0; j < nodes[i].OutEdgeCount; j++) { auxGoalBounds.connectionBounds[j] = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds(); auxGoalBounds.connectionBounds[j].InitializeBounds(nodes[i].Position); } if (i % 10 == 0) { float percentage = (float)i / (float)nodes.Count; EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Calculating goal bounds for each edge", percentage); } //run a Dijkstra mapflooding for each node dijkstra.Search(nodes[i], auxGoalBounds); goalBoundingTable.table[i] = auxGoalBounds; //edgeIndex++; } } BinaryFormatter bf = new BinaryFormatter(); if (File.Exists("Assets/GoalBoundingData/GoalBounding.dat")) { File.Delete("Assets/GoalBoundingData/GoalBounding.dat"); } FileStream file = File.Create("Assets/GoalBoundingData/GoalBounding.dat"); bf.Serialize(file, goalBoundingTable); file.Close(); EditorUtility.ClearProgressBar(); TimeSpan time = DateTime.Now - startTime; Debug.Log("Duration creating goalboundtable : " + time.ToString()); }
// Use this for initialization void Awake() { this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.character = new DynamicCharacter(this.characterAvatar); this.character.Drag = 0.5f; StringPullingPathSmoothing.MinWidth = 0.1f; this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanHeuristic()); //this.aStarPathFinding = new AStarPathfinding(this.navMesh, new SimpleUnorderedNodeList(), new SimpleUnorderedNodeList(), new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; }
public GoalBoundingNodeArrayAStarPathFinding(NavMeshPathGraph graph, IHeuristic heuristic) : base(graph, heuristic) { }
public GoalBoundingPathfinding(NavMeshPathGraph graph, IHeuristic heuristic, GoalBoundingTable goalBoundsTable) : base(graph, heuristic) { this.GoalBoundingTable = goalBoundsTable; dikjstra = new GoalBoundsDijkstraMapFlooding(graph); }
// Use this for initialization void Start() { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.aStarPathFinding = new AStarPathfinding(this.navMesh, new SimpleUnorderedNodeList(), new DictionaryData(), new ZeroHeuristic()); }
public InfluenceMapAStarPathfinding(NavMeshPathGraph graph, IHeuristic heuristic, InfluenceMap redMap, InfluenceMap greenMap) : base(graph,heuristic) { this.RedMap = redMap; this.GreenMap = greenMap; }
// Use this for initialization void Awake() { this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.character = new DynamicCharacter(this.characterAvatar); this.enemies = new List<DynamicCharacter>(); for (int i = 0; i < enemiesAvatar.Length; i++) { DynamicCharacter enemy = new DynamicCharacter(this.enemiesAvatar[i]); DynamicBackAndForth movement = new DynamicBackAndForth() { Character = enemy.KinematicData, MaxAcceleration = 10.0f, StopRadius = 2.0f, SlowRadius = 5.0f, MoveDistance = 25.0f }; movement.CalculatePositions(); enemy.Movement = movement; this.enemies.Add(enemy); } this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; }
// Use this for initialization void Awake() { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh,new ZeroHeuristic()); //this.aStarPathFinding = new AStarPathfinding(this.navMesh, new NodePriorityHeap(), new DictionaryData(), new ZeroHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; }
// Use this for initialization void Awake() { this.draw = false; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.character = new DynamicCharacter(this.characterAvatar); this.character.Drag = 0.3f; StringPullingPathSmoothing.MinWidth = 0.1f; this.aStarPathFindingEuclidean = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFindingGBEuclidean = new GoalBoundingNodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFindingZero = new NodeArrayAStarPathFinding(this.navMesh, new ZeroHeuristic()); this.aStarPathFindingGBZero = new GoalBoundingNodeArrayAStarPathFinding(this.navMesh, new ZeroHeuristic()); this.aStarPathFindingEuclidean.NodesPerSearch = 100; this.aStarPathFindingZero.NodesPerSearch = 100; this.aStarPathFindingGBEuclidean.NodesPerSearch = 100; this.aStarPathFindingGBEuclidean.NodesPerSearch = 100; //default this.aStarPathFinding = this.aStarPathFindingGBEuclidean; currentAStar = "A* GoalBounding Euclidean Distance"; }
public void Start() { this.draw = true; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); //initialization of the movement algorithms // this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); //this.aStarPathFinding.NodesPerSearch = 100; //initialization of the GOB decision making //let's start by creating 4 main goals //the eatgoal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { this.Actions.Add(new PickUpChest(this, chest)); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { this.Actions.Add(new GetArrows(this, tree)); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { this.Actions.Add(new Sleep(this, bed)); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } this.Character.Movement = InitializeSteeringPipeline(this.Character); }
public NodeAStarDecomposer() { this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; }
// Use this for initialization void Start() { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; IHeuristic heuristic = null; switch (Heuristic) { case HeuristicType.Zero: heuristic = new ZeroHeuristic(); break; case HeuristicType.Euclidean: heuristic = new EuclideanHeuristic(); break; default: break; } this.aStarPathFinding = new AStarPathfinding(this.navMesh, new SimpleUnorderedNodeList(), new HashTableNodeList(), heuristic); }
public override void RestartNodeArray(NavMeshPathGraph graph) { var nodes = this.GetNodesHack(graph); this.NodeRecordArray = new NodeRecordArray(nodes); }
public void Start() { this.draw = true; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.Character = new DynamicCharacter(this.gameObject) { Drag = 0.3f}; //initialization of the movement algorithms this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; var steeringPipeline = new Assets.Scripts.IAJ.Unity.SteeringPipeline.SteeringPipeline { MaxAcceleration = 40.0f, MaxConstraintSteps = 2, Character = this.Character.KinematicData, }; this.decomposer = new Assets.Scripts.IAJ.Unity.SteeringPipeline.NodeAStarDecomposer(this.aStarPathFinding); this.Targeter = new Assets.Scripts.IAJ.Unity.SteeringPipeline.TargetPosition(); steeringPipeline.Targeters.Add(this.Targeter); steeringPipeline.Decomposers.Add(this.decomposer); var obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); steeringPipeline.Constraints.Add( new Assets.Scripts.IAJ.Unity.SteeringPipeline.ConstraitColisionWithWalls(obstacles, 500.0f) { AvoidMargin = 7f, MaxLookAhead = 5f, MaxWhiskersLookAhead = 7f }); steeringPipeline.Actuator = actuator = new Assets.Scripts.IAJ.Unity.SteeringPipeline.PathFollowingActuator() { movement = new DynamicFollowPath() { MaxAcceleration = 40.0f, PathOffset = 0.05f, Movement = new DynamicCarSeek() { MaxSpeed = this.Character.MaxSpeed, MinSpeed = 4f } }, SecondsToSmooth = 2f }; this.Character.Movement = steeringPipeline; //initialization of the GOB decision making //let's start by creating 4 main goals //the eatgoal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { this.Actions.Add(new PickUpChest(this, chest)); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { this.Actions.Add(new GetArrows(this, tree)); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { this.Actions.Add(new Sleep(this, bed)); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } }
public void Start() { this.draw = true; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); //initialization of the movement algorithms this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; var steeringPipeline = new SteeringPipeline { MaxAcceleration = 40.0f, MaxConstraintSteps = 2, Character = this.Character.KinematicData, }; this.decomposer = new PathFindingDecomposer(steeringPipeline, this.aStarPathFinding); this.Targeter = new FixedTargeter(steeringPipeline); steeringPipeline.Targeters.Add(this.Targeter); steeringPipeline.Decomposers.Add(this.decomposer); steeringPipeline.Actuator = new FollowPathActuator(steeringPipeline); this.Character.Movement = steeringPipeline; //initialization of the GOB decision making //let's start by creating 4 main goals //the eatgoal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { this.Actions.Add(new PickUpChest(this, chest)); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { this.Actions.Add(new GetArrows(this, tree)); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { this.Actions.Add(new Sleep(this, bed)); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } var worldModel = new CurrentStateWorldModel(this.GameManager, this.Actions, this.Goals); this.GOAPDecisionMaking = new DepthLimitedGOAPDecisionMaking(worldModel,this.Actions,this.Goals); }
public virtual void RestartNodeArray(NavMeshPathGraph graph) { }
// Use this for initialization void Awake() { this.draw = false; this.currentClickNumber = 1; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanHeuristic()); //this.aStarPathFinding = new AStarPathfinding(this.navMesh, new RightPriorityList(), new HashTableNodeList(), new EuclideanHeuristic()); this.aStarPathFinding.NodesPerSearch = 50; }
// This will regenerate the navigation mesh when called public void GenerateNavmesh() { NavMeshRig tRig = GetComponent<NavMeshRig>(); // Unregister any navigation mesh we may already have (probably none if you are using this) tRig.NavMesh.UnregisterNavigationGraph(); tRig.NavMesh.Size = 40; tRig.NavMesh.MaxSlope = 45; tRig.NavMesh.WalkableHeight = 2; tRig.NavMesh.WalkableRadius = 3; tRig.NavMesh.StepHeight = 0.75f; tRig.NavMesh.CellSize = 0.5f; tRig.NavMesh.StartCreatingContours(_threadCount); while (tRig.NavMesh.Creating) { tRig.NavMesh.CreateContours(); // This could be changed to a yield (and the function to a coroutine) although as // of RAIN of 2.1.4.0 (fixed since then), our navigation mesh editor has issues with it Thread.Sleep(10); } tRig.NavMesh.RegisterNavigationGraph(); this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; }
private static void CreateClusterGraph() { Cluster cluster; Gateway gateway; //get cluster game objects var clusters = GameObject.FindGameObjectsWithTag("Cluster"); //get gateway game objects var gateways = GameObject.FindGameObjectsWithTag("Gateway"); //get the NavMeshGraph from the current scene NavMeshPathGraph navMesh = GameObject.Find("Navigation Mesh").GetComponent <NavMeshRig>().NavMesh.Graph; ClusterGraph clusterGraph = ScriptableObject.CreateInstance <ClusterGraph>(); //create gateway instances for each gateway game object for (int i = 0; i < gateways.Length; i++) { var gatewayGO = gateways[i]; gateway = ScriptableObject.CreateInstance <Gateway>(); gateway.Initialize(i, gatewayGO); clusterGraph.gateways.Add(gateway); } //create cluster instances for each cluster game object and check for connections through gateways foreach (var clusterGO in clusters) { cluster = ScriptableObject.CreateInstance <Cluster>(); cluster.Initialize(clusterGO); clusterGraph.clusters.Add(cluster); //determine intersection between cluster and gateways and add connections when they intersect foreach (var gate in clusterGraph.gateways) { if (MathHelper.BoundingBoxIntersection(cluster.min, cluster.max, gate.min, gate.max)) { cluster.gateways.Add(gate); gate.clusters.Add(cluster); } } } // Second stage of the algorithm, calculation of the Gateway table GlobalPath solution = null; //float cost; Gateway startGate; Gateway endGate; var pathfindingAlgorithm = new NodeArrayAStarPathFinding(navMesh, new EuclideanDistanceHeuristic()); clusterGraph.gatewayDistanceTable = new GatewayDistanceTableRow[clusterGraph.gateways.Count]; for (int i = 0; i < clusterGraph.gateways.Count; i++) { var row = new GatewayDistanceTableRow(); row.entries = new GatewayDistanceTableEntry[clusterGraph.gateways.Count]; startGate = clusterGraph.gateways[i]; for (int j = 0; j < clusterGraph.gateways.Count; j++) { endGate = clusterGraph.gateways[j]; row.entries[j] = new GatewayDistanceTableEntry() { startGatewayPosition = startGate.Localize(), endGatewayPosition = endGate.Localize() }; if (i != j) { pathfindingAlgorithm.InitializePathfindingSearch(startGate.Localize(), endGate.Localize()); bool finished = pathfindingAlgorithm.Search(out solution); if (finished && solution != null) { row.entries[j].shortestDistance = solution.Length; } else { row.entries[j].shortestDistance = float.MaxValue; } } else { row.entries[j].shortestDistance = 0.0f; } } clusterGraph.gatewayDistanceTable[i] = row; } //Debug.Log("Distance table with: " + clusterGraph.gatewayDistanceTable.Length + " rows and " + clusterGraph.gatewayDistanceTable[0].entries.Length + " columns."); //string print = "["; //for (int i = 0; i < clusterGraph.gatewayDistanceTable.Length; i++) //{ // print += "["; // for(int j= 0; j < clusterGraph.gatewayDistanceTable[i].entries.Length; j++) // { // print += clusterGraph.gatewayDistanceTable[i].entries[j].shortestDistance + ", "; // } // print += "]\n"; //} //print += "]"; //Debug.Log(print); //do not change this var nodes = GetNodesHack(navMesh); clusterGraph.nodesCluster = new Cluster[nodes.Count]; foreach (var n in nodes) { var pos = n.LocalPosition; foreach (var c in clusterGraph.clusters) { if (pos.x >= c.min.x && pos.x <= c.max.x && pos.z >= c.min.z && pos.z <= c.max.z) { clusterGraph.nodesCluster[n.NodeIndex] = c; break; } } } //create a new asset that will contain the ClusterGraph and save it to disk (DO NOT REMOVE THIS LINE) clusterGraph.SaveToAssetDatabase(); }
public void Start() { this.draw = true; this.influenceMapDebugMode = 0; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); //initialization of the movement algorithms this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; var steeringPipeline = new Assets.Scripts.IAJ.Unity.SteeringPipeline.SteeringPipeline { MaxAcceleration = 40.0f, MaxConstraintSteps = 2, Character = this.Character.KinematicData, }; this.decomposer = new Assets.Scripts.IAJ.Unity.SteeringPipeline.NodeAStarDecomposer(this.aStarPathFinding); this.Targeter = new Assets.Scripts.IAJ.Unity.SteeringPipeline.TargetPosition(); steeringPipeline.Targeters.Add(this.Targeter); steeringPipeline.Decomposers.Add(this.decomposer); steeringPipeline.Actuator = actuator = new Assets.Scripts.IAJ.Unity.SteeringPipeline.PathFollowingActuator() { movement = new DynamicFollowPath() { MaxAcceleration = 40.0f, PathOffset = 0.05f, Movement = new DynamicCarSeek() { MaxSpeed = this.Character.MaxSpeed, MinSpeed = 4f } }, SecondsToSmooth = 2f }; this.Character.Movement = steeringPipeline; //initialization of the Influence Maps this.RedInfluenceMap = new InfluenceMap(this.navMesh,new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); this.GreenInfluenceMap = new InfluenceMap(this.navMesh, new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); //initialization of the GOB decision making //let's start by creating 4 main goals //the eatgoal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.ConquerGoal = new Goal(CONQUER_GOAL, 1.5f) { InsistenceValue = 5.0f }; this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); this.Goals.Add(this.ConquerGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { this.Actions.Add(new PickUpChest(this, chest)); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { this.Actions.Add(new GetArrows(this, tree)); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { this.Actions.Add(new Sleep(this, bed)); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } //flags used for the influence map this.RedFlags = new List<IInfluenceUnit>(); foreach (var redFlag in GameObject.FindGameObjectsWithTag("RedFlag")) { this.RedFlags.Add(new Flag(this.navMesh.QuantizeToNode(redFlag.transform.position, 1.0f), FlagColor.Red)); } this.GreenFlags = new List<IInfluenceUnit>(); foreach (var greenFlag in GameObject.FindGameObjectsWithTag("GreenFlag")) { this.GreenFlags.Add(new Flag(this.navMesh.QuantizeToNode(greenFlag.transform.position, 1.0f), FlagColor.Green)); } this.RedInfluenceMap.Initialize(this.RedFlags); this.GreenInfluenceMap.Initialize(this.GreenFlags); var worldModel = new CurrentStateWorldModel(this.GameManager, this.Actions, this.Goals); this.GOAPDecisionMaking = new DepthLimitedGOAPDecisionMaking(worldModel,this.Actions,this.Goals); }
public GoalBoundingPathfinding(NavMeshPathGraph graph, IHeuristic heuristic, GoalBoundingTable goalBoundsTable) : base(graph, heuristic) { this.GoalBoundingTable = goalBoundsTable; }
public void Start() { navMesh = NavigationManager.Instance.NavMeshGraphs[0]; }