Пример #1
0
        // Following Camera.

        private void StartFollowMode()
        {
            mode = Mode.Follow;
            FindCluster();

            targetDamp      = followTargetDamp;
            cameraDamp      = followCameraDamp;
            isFollowingTail = !isFollowingTail;
            targetAgent     = isFollowingTail ? clusterTail : clusterLead;
            followZOffset   = isFollowingTail ? followTailZOffset : followLeadZOffset;
            Invoke("StopFollowMode", Random.Range(followMinDuration, followMaxDuration));
        }
Пример #2
0
        // Stationary Camera.

        private void StartSidelineMode()
        {
            mode = Mode.Sideline;
            FindCluster();

            targetDamp  = sidelineTargetDamp;
            cameraDamp  = sidelineCameraDamp;
            targetAgent = clusterTail;
            sidelinePos = track.Positions.AtDegree(
                clusterLead.Shared.CrntPos.PosDeg + sidelineZOffset);
            cameraPos =
                sidelinePos.PosV3 +
                sidelinePos.Orthogonal * sidelineXOffset * Mathf.Sign(sidelinePos.Curvature) +
                sidelinePos.Normal * sidelineYOffset;
        }
Пример #3
0
        private void FindCluster()
        {
            cluster.Clear();
            for (int i = 0; i < agents.Length; i++)
            {
                var tmp = new List <BikeAgent>();
                for (int j = 0; j < agents.Length; j++)
                {
                    if (Mathf.Abs(Mathf.DeltaAngle(agents[i].Shared.CrntPos.PosDeg,
                                                   agents[j].Shared.CrntPos.PosDeg)) < clusterLooseness)
                    {
                        tmp.Add(agents[j]);
                    }
                }
                if (tmp.Count > cluster.Count)
                {
                    cluster = tmp;
                }
            }

            if (cluster.Count == 1)
            {
                // No cluster, find closest excl. previous target.
                float min = Mathf.Infinity;
                foreach (BikeAgent agent in agents)
                {
                    float d = (smoothCameraPos - agent.Position).sqrMagnitude;
                    if (d < min && agent != targetAgent)
                    {
                        min = d;
                        cluster.Clear();
                        cluster.Add(agent);
                    }
                }
            }
            else
            {
                cluster.Sort();
            }

            clusterTail = cluster[0];
            clusterLead = cluster[cluster.Count - 1];
        }
 private void FindCluster()
 {
     cluster.Clear();
     for (int i = 0; i < agents.Length; i++)
     {
         var tmp = new List <BikeAgent>();
         for (int j = 0; j < agents.Length; j++)
         {
             if (Mathf.Abs(Mathf.DeltaAngle(agents[i].Shared.CrntPos.PosDeg,
                                            agents[j].Shared.CrntPos.PosDeg)) < clusterLooseness)
             {
                 tmp.Add(agents[j]);
             }
         }
         if (tmp.Count > cluster.Count)
         {
             cluster = tmp;
         }
     }
     cluster.Sort();
     clusterTail = cluster[0];
     clusterLead = cluster[cluster.Count - 1];
 }
 private void PickAgent()
 {
     FindCluster();
     isTailing = !isTailing; // RndFlip();
     camAgent  = isTailing ? clusterTail : clusterLead;
 }