Ejemplo n.º 1
0
        public void UpdateChannels(Goal other)
        {
            this.HasPosition = other.HasPosition;
            if (other.HasPosition)
            {
                this.position = other.position;
            }

            this.HasOrientation = other.HasOrientation;
            if (other.HasOrientation)
            {
                this.orientation = other.orientation;
            }

            this.HasVelocity = other.HasVelocity;
            if (other.HasVelocity)
            {
                this.velocity = other.velocity;
            }

            this.HasRotation = other.HasRotation;
            if (other.HasRotation)
            {
                this.rotation = other.rotation;
            }

            this.IsNew = other.IsNew;

            if (other.Path != null)
            {
                Path = other.Path;
                this.CurrentParam = other.CurrentParam;
            }
        }
        public Goal Suggest(KinematicData character, GlobalPath path, Goal goal)
        {
            Vector3 characterPoint = NavigationManager.Instance.NavMeshGraphs [0].ClosestPointOnGraph(character.position, aMaxYOffset);
            NavigationGraphNode characterNodeInGraph = NavigationManager.Instance.NavMeshGraphs [0].QuantizeToNode(characterPoint, 1.0f);

            Vector3 suggestedPoint = NavigationManager.Instance.NavMeshGraphs [0].ClosestPointOnGraph(suggestedPosition, aMaxYOffset);
            NavigationGraphNode nodeInGraph = NavigationManager.Instance.NavMeshGraphs [0].QuantizeToNode(suggestedPoint, 1.0f);

            Debug.DrawRay(characterPoint, (suggestedPoint - characterPoint), Color.cyan);

            Goal suggestedGoal = new Goal()
            {
                HasPosition = true,
                position = suggestedPoint,
                IsNew = true
            };

            GlobalPath suggestedPath = new GlobalPath();
            suggestedPath.PathPositions.Add(characterPoint);
            suggestedPath.PathPositions.Add(suggestedPoint);
            suggestedPath.PathNodes.Add(characterNodeInGraph);
            suggestedPath.PathNodes.Add(nodeInGraph);

            suggestedPath.CalculateLocalPathsFromPathPositions(characterPoint);

            suggestedGoal.Path = suggestedPath;

            forgive = true;

            return suggestedGoal;
        }
Ejemplo n.º 3
0
 public GlobalPath GetPath(KinematicData character, Goal goal)
 {
     if (goal.HasPosition && goal.Path != null)
     {
         return goal.Path;
     }
     return null;
 }
 public MovementOutput GetMovement(KinematicData character, GlobalPath path, Goal goal)
 {
     if (goal.HasPosition && path != null)
     {
         movement.Character = character;
         movement.Path = path;
         movement.CurrentParam = goal.CurrentParam;
         MovementOutput movementOut = movement.GetMovement();
         goal.CurrentParam = movement.CurrentParam;
         return movementOut;
     }
     return movement.EmptyMovementOutput;
 }
 public GlobalPath GetPath(Movement.KinematicData character, Goal goal)
 {
     if (goal.HasPosition && goal.Path != null)
     {
         float actualTime = Time.realtimeSinceStartup;
         if (actualTime - previousSmooth > SecondsToSmooth ||
             currentSmoothedSolution == null ||
             goal.IsNew ||
             goal != previousGoal)
         {
             previousSmooth = actualTime;
             currentSmoothedSolution = StringPullingPathSmoothing.SmoothPath(character, goal.Path);
             currentSmoothedSolution.CalculateLocalPathsFromPathPositions(character.position);
         }
         previousGoal = goal;
         return currentSmoothedSolution;
     }
     return null;
 }
 public Goal Decompose(KinematicData character, Goal goal)
 {
     if (goal != null && goal.HasPosition)
     {
         if (goal.IsNew)
         {
             this.aStarPathFinding.InitializePathfindingSearch(character.position, goal.position);
             this.currentSolution = null;
         }
         if (this.aStarPathFinding.InProgress)
         {
             this.aStarPathFinding.Search(out this.currentSolution, true);
             if (currentSolution != null)
             {
                 goal.Path = currentSolution;
                 goal.Path.CalculateLocalPathsFromPathPositions(character.position);
             }
         }
     }
     return goal;
 }
 public Goal Decompose(KinematicData character, Goal goal)
 {
     personPath.LocalPaths [0] = new LineSegmentPath(character.position, goal.position);
     goal.Path = personPath;
     return goal;
 }
        public override MovementOutput GetMovement()
        {
            if (goal == null)
            {
                goal = storedGoal;
            }

            if (goal != null && goal.IsMain)
            {
                foreach (ITargeter targeter in Targeters)
                {
                    goal.UpdateChannels(targeter.GetGoal(this.Character));
                }

                foreach (IDecomposer decomposer in Decomposers)
                {
                    goal = decomposer.Decompose(Character, goal);
                }

                storedGoal = goal;
            }

            bool validPath = false;
            GlobalPath path = null;
            for (int i = 0; i < this.MaxConstraintSteps; i++)
            {
                validPath = true;
                path = Actuator.GetPath(this.Character, goal);
                if (path != null)
                {
                    foreach (IConstraint constraint in Constraints)
                    {
                        if (constraint.WillViolate(this.Character, path))
                        {
                            validPath = false;
                            goal = constraint.Suggest(Character, path, goal);
                            break;
                        }
                    }
                    if (validPath)
                    {
                        break;
                    }
                }
            }

            MovementOutput movement = null;
            if (validPath)
            {
                movement = Actuator.GetMovement(Character, path, goal);
            }
            else
            {
                movement = EmptyMovement;
            }

            if (goal != null)
            {
                if (goal.IsNew)
                {
                    goal.IsNew = false;
                }
                if (!goal.IsMain && goal.CurrentParam >= 0.33)
                {
                    goal = null;
                }
            }
            return movement;
        }