Esempio n. 1
0
        public override TargetGoal GetGoal(KinematicData character)
        {
            TargetGoal g = new TargetGoal() { position = Target.position + (Target.velocity * LookAhead )};
            g.hasPosition = true;

            return g;
        }
Esempio n. 2
0
        public override MovementOutput GetMovement()
        {
            TargetGoal g = new TargetGoal();
            foreach (Targeter t in Targeters)
            {
                g.UpdateChannels(t.GetGoal(Character));
            }

            foreach (Decomposer d in Decomposers)
            {
                g = d.Decompose(Character, g);
            }

            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();
        }
Esempio n. 3
0
        public override TargetGoal Suggest(LineSegmentPath path, KinematicData character, TargetGoal 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;
        }
Esempio n. 4
0
        public override TargetGoal Suggest(LineSegmentPath path, KinematicData character, TargetGoal 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*/
        }
Esempio n. 5
0
        public override TargetGoal GetGoal(KinematicData character)
        {
            if (!this.hasTarget)
                return new TargetGoal();

            TargetGoal g = new TargetGoal() { position = this.Target.position };
            g.hasPosition = true;

            return g;
        }
Esempio n. 6
0
        public override TargetGoal Decompose(KinematicData character, TargetGoal goal)
        {
            if (!goal.hasPosition)
                return new TargetGoal();

            if (lastGoal == null || !lastGoal.position.Equals(goal.position)) {
                Astar = new NodeArrayAStarPathFinding(Graph, Heuristic);
                Astar.InitializePathfindingSearch(character.position, goal.position);
                CurrentParam = 0.0f;
                this.lastGoal = goal;
            }

            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);

                CurrentParam += GlobalPath.CalculateOffset(CurrentParam);

                 goal.position = GlobalPath.GetPosition(CurrentParam);
                 return goal;
             }
            return new TargetGoal();
        }
Esempio n. 7
0
 public void UpdateChannels(TargetGoal 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;
     }
 }
Esempio n. 8
0
        public override TargetGoal Decompose(KinematicData character, TargetGoal 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;
        }
Esempio n. 9
0
 public abstract TargetGoal Decompose(KinematicData character, TargetGoal goal);
Esempio n. 10
0
 public abstract TargetGoal Suggest(LineSegmentPath path, KinematicData character, TargetGoal goal);