Example #1
0
        public override bool Tick()
        {
            Entity       agent = context.agent;
            WaypointPath path  = context.path;

            Debug.Assert(path != null, nameof(path) + " != null");

            WaypointTracker tracker       = path.GetTrackerForEntity(context.agent.index);
            int             completedLaps = tracker.CompletedLaps;

            Vector3 waypoint = tracker.CurrentWaypoint;

            float distSquared = agent.transformInfo.DistanceToSquared(waypoint);

            if (distSquared < 20 * 20)   // todo replace with a radius per waypoint
            {
                tracker.Progress();
            }

            waypoint = tracker.CurrentWaypoint;
            ApproachType approachType = tracker.IsFinalWaypoint ? ApproachType.Arrive : ApproachType.Normal;

            agent.FlightSystem.SetTargetPosition(waypoint, approachType);
            return(tracker.CompletedLaps != completedLaps);
        }
        protected override float Score(WaypointContext context)
        {
            WaypointPath path = context.path;

            if (path == null)
            {
                return(0);
            }
            WaypointTracker tracker     = path.GetTrackerForEntity(context.agent.index);
            Vector3         waypoint    = tracker.CurrentWaypoint;
            float           distSquared = context.agent.transformInfo.DistanceToSquared(waypoint);

            return(MathUtil.PercentageOfRangeClamped(distSquared, minDist * minDist, maxDist * maxDist));
        }