public override MovementOutput GetMovement() { Goal g = new Goal(); foreach (Targeter t in Targeters) { g.UpdateChannels(t.GetGoal(Character)); } foreach (Decomposer d in Decomposers) { g = d.Decompose(Character, g); } // bool ValidPath = false; TO DO esta parte ta uma bequita meh for (int i = 0; i <= MaxConstraintSteps; i++) { Actuator.goal = g; LineSegmentPath path = Actuator.GetPath(); foreach (Constraint c in Constraints) { if (c.WillViolate(path)) { g = c.Suggest(path, Character, g); continue; } } return Actuator.GetMovement(); } return DeadlockMovement.GetMovement(); }
public override Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal) { // procurar ponto do segmento mais próximo ao centro da esfera Vector3 closest = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, Troll.KinematicData.position)); // Check if we pass through the center point Vector3 newPt; if (closest.sqrMagnitude == 0) { // Get any vector at right angles to the segment Vector3 dirn = path.EndPosition - path.StartPosition; //pode nao ser esta func TO DO Vector3 newdirn = Vector3.Cross(dirn, Vector3.Cross(dirn, Vector3.forward)); newPt = Troll.KinematicData.position + newdirn * TrollRadius * margin; } else { // Otherwise project the point out beyond the radius newPt = (Troll.KinematicData.position + (closest - Troll.KinematicData.position) * TrollRadius * margin) / closest.sqrMagnitude; } // Set up the goal and return goal.position = newPt; return goal; }
public override Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal) { if (this.chars.KinematicData.velocity.sqrMagnitude > 1.5f) { this.chars.KinematicData.velocity *= 0.01f; } return goal; /* // procurar ponto do segmento mais próximo ao centro da esfera Vector3 closest = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, chars.KinematicData.position)); // Check if we pass through the center point Vector3 newPt; float i = 1.0f; while (i < 25.0f) { for(int a = 0; a < 360; a++) { float nx = (float) (closest.sqrMagnitude * i * Math.Cos((a * (Math.PI / 180)))); float ny = (float) (closest.sqrMagnitude * i * Math.Sin((a * (Math.PI / 180)))); newPt = new Vector3(nx, closest.y,ny); if (navMeshP.IsPointOnGraph(newPt)) { goal.position = newPt; return goal; } } i = i + 0.25f; } return goal; // Set up the goal and return*/ }
public Goal GetGoal(KinematicData character) { Goal g = new Goal() { position = Target.position + (Target.velocity * LookAhead )}; g.hasPosition = true; return g; }
public override Goal Decompose(KinematicData character, Goal goal) { if((Astar == null)) { Astar = new NodeArrayAStarPathFinding(Graph, Heuristic); Astar.InitializePathfindingSearch(character.position, goal.position); CurrentParam = 0.0f; } GlobalPath currentSolution; if (Astar.InProgress) { var finished = Astar.Search(out currentSolution, true); if (finished && currentSolution != null) { this.AStarSolution = currentSolution; this.GlobalPath = StringPullingPathSmoothing.SmoothPath(character, currentSolution); this.GlobalPath.CalculateLocalPathsFromPathPositions(character.position); // gets first node goal.position = this.GlobalPath.LocalPaths[0].EndPosition; return goal; } /* else if(currentSolution != null && currentSolution.IsPartial) { goal.position = currentSolution.PathPositions[0]; return goal; }*/ } else { if (GlobalPath.PathEnd(CurrentParam)) { goal.position = GlobalPath.LocalPaths[GlobalPath.LocalPaths.Count - 1].GetPosition(1.0f); return goal; } CurrentParam = GlobalPath.GetParam(character.position, CurrentParam); goal.position = GlobalPath.GetPosition(CurrentParam + 0.2f); return goal; } return new Goal(); }
public void UpdateChannels(Goal o) { if (o.hasPosition) { position = o.position; hasPosition = true; } if (o.hasOrientation) { orientation = o.orientation; hasOrientation = true; } if (o.hasVelocity) { velocity = o.velocity; hasVelocity = true; } if (o.hasRotation) { rotation = o.rotation; hasRotation = true; } }
public override Goal Decompose(KinematicData character, Goal goal) { AStarPathfinding Astar = new NodeArrayAStarPathFinding(Graph, Heuristic); Astar.InitializePathfindingSearch(character.position, goal.position); // In goal, ends if (Astar.StartNode.Equals(Astar.GoalNode)) { return goal; } // else, plan GlobalPath currentSolution; if (Astar.InProgress) { var finished = Astar.Search(out currentSolution, true); if (finished && currentSolution != null) { // gets first node goal.position = currentSolution.PathNodes[0].Position; return goal; } } return goal; }
public abstract Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal);
public abstract Goal Decompose(KinematicData character, Goal goal);