コード例 #1
0
        public override SteeringOutput GetSteering(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
        {
            SteeringOutput output = new SteeringOutput();

            if (targetLastPosition != null)
            {
                output = VelocityMatch(character, agentLocalBehaviour.target.transform.position, targetLastPosition, Time.fixedDeltaTime);
            }
            targetLastPosition = agentLocalBehaviour.target.transform.position;

            return(output);
        }
コード例 #2
0
        public SteeringOutput Wander(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
        {
            SteeringOutput output = new SteeringOutput();

            // update wander angle with [-wanderRate;wanderRate]
            agentLocalBehaviour.wanderAngle += (UnityEngine.Random.value * 2f - 1f) * wanderRate;

            Vector3 targetCircleCenter = character.transform.position + character.transform.up * wanderOffset;
            // move from center of circle by a vector with wanderAngle angle and wanderRadius length
            Vector3 targetOnCircleLocation = targetCircleCenter +
                                             Quaternion.Euler(0, 0, agentLocalBehaviour.wanderAngle) * character.transform.up * wanderRadius;

            if (character.showGizmos)
            {
                Debug.DrawLine(character.transform.position, targetOnCircleLocation, Color.red);
            }

            // get rotation
            output = Face(character, targetOnCircleLocation);
            // set linear to full acceleration ahead
            output.linear = character.transform.up * character.maxAcceleration;

            return(output);
        }
コード例 #3
0
 public override SteeringOutput GetSteering(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
 {
     return(Flee(character, agentLocalBehaviour.target.transform.position));
 }
コード例 #4
0
        public SteeringOutput FollowPath(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
        {
            SteeringOutput output = new SteeringOutput();

            // Debug.Log(agentLocalBehaviour.currentPathStation + " " + agentLocalBehaviour.path.GetNextStationIndex(agentLocalBehaviour.currentPathStation));
            switch (followType)
            {
            case FollowType.Station:
                #region Station
                // in agentLocalBehaviour we store the current station that is being followed
                // so we need to check whether the agent is closer to that station or the next one
                // to check that we need to get the position

                // if the current path is farther away then the next path
                if ((agentLocalBehaviour.path.GetDistanceFromPathTo(character.transform.position, agentLocalBehaviour.currentPathStation) >
                     agentLocalBehaviour.path.GetDistanceFromPathTo(character.transform.position, agentLocalBehaviour.path.GetNextStationIndex(agentLocalBehaviour.currentPathStation)))
                    // or we have reached the station
                    || Vector3.Distance(character.transform.position, agentLocalBehaviour.path.GetStationPosition(agentLocalBehaviour.currentPathStation)) <= targetRadius)
                {
                    // make the next station the target
                    agentLocalBehaviour.currentPathStation = agentLocalBehaviour.path.GetNextStationIndex(agentLocalBehaviour.currentPathStation);
                }

                output = Seek(character, agentLocalBehaviour.path.GetStationPosition(agentLocalBehaviour.currentPathStation));
                #endregion
                break;

            case FollowType.AlwaysReachStation:
                #region AlwaysReachStation
                // we have reached the station
                if (Vector3.Distance(character.transform.position, agentLocalBehaviour.path.GetStationPosition(agentLocalBehaviour.currentPathStation)) <= targetRadius)
                {
                    // make the next station the target
                    agentLocalBehaviour.currentPathStation = agentLocalBehaviour.path.GetNextStationIndex(agentLocalBehaviour.currentPathStation);
                }

                output = Seek(character, agentLocalBehaviour.path.GetStationPosition(agentLocalBehaviour.currentPathStation));
                #endregion
                break;

            case FollowType.Path:
                #region Path
                // here we look ahead on the path with followAheadPercent and set that as a target

                float   percent = agentLocalBehaviour.path.GetClosestPointOnPathPercent(character.transform.position);
                Vector3 target  = agentLocalBehaviour.path.GetPointOnPathPercent(percent + followAheadPercent);
                output = Seek(character, target);

                if (character.showGizmos)
                {
                    Debug.DrawLine(character.transform.position, target, Color.green);
                }
                #endregion
                break;

            case FollowType.PredictivePath:
                #region Predictive Path
                percent = agentLocalBehaviour.path.GetClosestPointOnPathPercent(character.transform.position + character.Velocity * predictTime);
                target  = agentLocalBehaviour.path.GetPointOnPathPercent(percent + followAheadPercent);
                output  = Seek(character, target);

                if (character.showGizmos)
                {
                    Debug.DrawLine(character.transform.position, character.transform.position + character.Velocity * predictTime, Color.yellow);
                    Debug.DrawLine(character.transform.position, target, Color.green);
                }
                #endregion
                break;
            }

            return(output);
        }
コード例 #5
0
 public override SteeringOutput GetSteering(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
 {
     return(FollowPath(character, agentLocalBehaviour));
 }
コード例 #6
0
 public override SteeringOutput GetSteering(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
 {
     return(Align(character, agentLocalBehaviour.transform.eulerAngles));
 }
コード例 #7
0
 public override SteeringOutput GetSteering(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour)
 {
     return(LookWhereYoureGoing(character));
 }
コード例 #8
0
 public abstract SteeringOutput GetSteering(AutonomousAgent character, WeightedSteeringBehaviour agentLocalBehaviour);