private int snapDistance = 20; // this should be a function of step and stepSize #endregion Fields #region Constructors /// <summary> /// Create a NPC. /// AGXNASK distribution has npAgent move following a Path. /// </summary> /// <param name="theStage"> the world</param> /// <param name="label"> name of </param> /// <param name="pos"> initial position </param> /// <param name="orientAxis"> initial rotation axis</param> /// <param name="radians"> initial rotation</param> /// <param name="meshFile"> Direct X *.x Model in Contents directory </param> public NPAgent(Stage theStage, string label, Vector3 pos, Vector3 orientAxis, float radians, string meshFile) : base(theStage, label, pos, orientAxis, radians, meshFile) { // change names for on-screen display of current camera first.Name = "npFirst"; follow.Name = "npFollow"; above.Name = "npAbove"; // path is built to work on specific terrain, make from int[x,z] array pathNode path = new Path(stage, pathNode, Path.PathType.LOOP); // continuous search path stage.Components.Add(path); nextGoal = path.NextNode; // get first path goal agentObject.turnToFace(nextGoal.Translation); // orient towards the first path goal // set snapDistance to be a little larger than step * stepSize snapDistance = (int) (1.5 * (agentObject.Step * agentObject.StepSize)); }
public void buildGraph() { List<NavNode> list = new List<NavNode>(); for (int x = 0; x < 513; x = x + 21) for (int z = 0; z < 513; z = z + 21) { NavNode node = new NavNode(new Vector3(x * spacing, stage.Terrain.surfaceHeight(x, z), z * spacing), NavNode.NavNodeEnum.WAYPOINT); for (int i = 0; i < stage.Collidable.Count; i++) { if (accessible(node.Translation, stage.Collidable[i].Translation, stage.Collidable[i].ObjectBoundingSphereRadius)) list.Add(node); } graph.Add(skey(x, z), node); open.Add(node); } NavNode node_treasure = new NavNode(new Vector3( 457, stage.Terrain.surfaceHeight(457, 453), 453), NavNode.NavNodeEnum.WAYPOINT); list.Add(node_treasure); graph.Add(skey(457, 453), node_treasure); open.Add(node_treasure); node_treasure = new NavNode(new Vector3(435, stage.Terrain.surfaceHeight(435, 424), 424), NavNode.NavNodeEnum.WAYPOINT); list.Add(node_treasure); graph.Add(skey(435, 424), node_treasure); open.Add(node_treasure); node_treasure = new NavNode(new Vector3(465, stage.Terrain.surfaceHeight(465, 453), 453), NavNode.NavNodeEnum.WAYPOINT); list.Add(node_treasure); graph.Add(skey(465, 453), node_treasure); open.Add(node_treasure); node_treasure = new NavNode(new Vector3(485, stage.Terrain.surfaceHeight(485, 420), 420), NavNode.NavNodeEnum.WAYPOINT); list.Add(node_treasure); graph.Add(skey(485, 420), node_treasure); open.Add(node_treasure); node_treasure = new NavNode(new Vector3(424, stage.Terrain.surfaceHeight(424, 444), 444), NavNode.NavNodeEnum.WAYPOINT); list.Add(node_treasure); graph.Add(skey(425, 444), node_treasure); open.Add(node_treasure); Path path = new Path(stage, list, Path.PathType.SINGLE); stage.Components.Add(path); }