Ejemplo n.º 1
0
 // Token: 0x06000C22 RID: 3106 RVA: 0x0004C964 File Offset: 0x0004AD64
 private void Update()
 {
     if (this.progressStyle == WaypointProgressTracker.ProgressStyle.SmoothAlongRoute)
     {
         if (Time.deltaTime > 0f)
         {
             this.speed = Mathf.Lerp(this.speed, (this.lastPosition - base.transform.position).magnitude / Time.deltaTime, Time.deltaTime);
         }
         this.target.position = this.circuit.GetRoutePoint(this.progressDistance + this.lookAheadForTargetOffset + this.lookAheadForTargetFactor * this.speed).position;
         this.target.rotation = Quaternion.LookRotation(this.circuit.GetRoutePoint(this.progressDistance + this.lookAheadForSpeedOffset + this.lookAheadForSpeedFactor * this.speed).direction);
         this.progressPoint   = this.circuit.GetRoutePoint(this.progressDistance);
         Vector3 lhs = this.progressPoint.position - base.transform.position;
         if (Vector3.Dot(lhs, this.progressPoint.direction) < 0f)
         {
             this.progressDistance += lhs.magnitude * 0.5f;
         }
         this.lastPosition = base.transform.position;
     }
     else
     {
         if ((this.target.position - base.transform.position).magnitude < this.pointToPointThreshold)
         {
             this.progressNum = (this.progressNum + 1) % this.circuit.Waypoints.Length;
         }
         this.target.position = this.circuit.Waypoints[this.progressNum].position;
         this.target.rotation = this.circuit.Waypoints[this.progressNum].rotation;
         this.progressPoint   = this.circuit.GetRoutePoint(this.progressDistance);
         Vector3 lhs2 = this.progressPoint.position - base.transform.position;
         if (Vector3.Dot(lhs2, this.progressPoint.direction) < 0f)
         {
             this.progressDistance += lhs2.magnitude;
         }
         this.lastPosition = base.transform.position;
     }
 }
        private void Update()
        {
            if (!circuit)
            {
                return;
            }

            if (progressStyle == ProgressStyle.SmoothAlongRoute)
            {
                // determine the position we should currently be aiming for
                // (this is different to the current progress position, it is a a certain amount ahead along the route)
                // we use lerp as a simple way of smoothing out the speed over time.
                if (Time.deltaTime > 0)
                {
                    speed = Mathf.Lerp(speed, (lastPosition - transform.position).magnitude / Time.deltaTime,
                                       Time.deltaTime);
                }
                target.position =
                    circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor * speed)
                    .position;
                target.rotation =
                    Quaternion.LookRotation(
                        circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor * speed)
                        .direction);


                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude * 0.5f;
                }

                lastPosition = transform.position;
            }
            else
            {
                // point to point mode. Just increase the waypoint if we're close enough:

                Vector3 targetDelta = target.position - transform.position;
                if (targetDelta.magnitude < pointToPointThreshold)
                {
                    progressNum = (progressNum + 1) % circuit.Waypoints.Length;
                }


                target.position = circuit.Waypoints[progressNum].position;
                target.rotation = circuit.Waypoints[progressNum].rotation;

                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude;
                }
                lastPosition = transform.position;
            }
        }
Ejemplo n.º 3
0
    void Update()
    {
        if (Track != null && target != null && pathExist)
        {
            target.position = Track.GetRoutePoint(progressDistance + 1.45f).position;                                                           // find the next position for the target
            target.rotation = Quaternion.LookRotation(Track.GetRoutePoint(progressDistance).direction);                                         // find the new rotation for the target


            progressPoint = Track.GetRoutePoint(progressDistance);                                                                                                              // --> Get the progressPoint position
            Vector3 progressDelta = progressPoint.position - transform.position;
            if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)                                                                                                        // if progress point position is behind the car
            {
                progressDistance += progressDelta.magnitude * 0.5f;                                                                                                             // change the progress point position
            }
        }

        if (Track != null && progressDistance / Track.Length > 1)
        {
            //Debug.Log ("Lap");
            iLapCounter++;
            if (sLapCounter)
            {
                sLapCounter.displayLap(carPathFollow);
            }
            progressDistance = progressDistance % Track.Length;
        }
    }
Ejemplo n.º 4
0
        private void Update()
        {
            if (progressStyle == ProgressStyle.SmoothAlongRoute)
            {
                var targetPosition =
                    circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset)
                    .position;

                projectedDistance = (transform.position - targetPosition).magnitude;

                transform.position =
                    Vector3.Lerp(
                        transform.position,
                        circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor * projectedDistance).position,
                        Time.deltaTime);

                transform.rotation =
                    Quaternion.Lerp(
                        transform.rotation,
                        Quaternion.LookRotation(
                            circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor * projectedDistance)
                            .direction),
                        Time.deltaTime);

                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - target.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude * 0.5f;
                }
            }
            else
            {
                // point to point mode. Just increase the waypoint if we're close enough:

                Vector3 targetDelta = target.position - transform.position;
                if (targetDelta.magnitude < pointToPointThreshold)
                {
                    progressNum = (progressNum + 1) % circuit.Waypoints.Length;
                }


                target.position = circuit.Waypoints[progressNum].position;
                target.rotation = circuit.Waypoints[progressNum].rotation;

                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude;
                }
            }
        }
Ejemplo n.º 5
0
//		public void SetIsStopMoveTarget(bool isStop)
//		{
//			IsStopMoveTarget = isStop;
//		}

        private void Update()
        {
            /*if (Input.GetKeyUp(KeyCode.P)) {
             *      SetCarPathInfo(circuit); //test
             * }*/

            if (IsStopMoveTarget)
            {
                return;
            }

            if (progressStyle == ProgressStyle.SmoothAlongRoute)
            {
                Vector3 vecA = circuit.Waypoints[progressNum].position - transform.position;
                Vector3 vecB = transform.forward;
                if (vecA.magnitude < 15f)
                {
                    vecA.y = vecB.y = 0f;
                    if (Vector3.Dot(vecA, vecB) < 0f)
                    {
                        NpcMark markScript = circuit.Waypoints[progressNum].GetComponent <NpcMark>();
                        if (markScript != null)
                        {
                            AiCarCom.SetAiCarTopMoveSpeed(markScript.MvSpeed);
                        }

                        progressNum++;
                        if (progressNum >= circuit.Waypoints.Length)
                        {
                            progressNum      = 0;
                            IsStopMoveTarget = true;
                            //stop move AiCar.
                            AiCarCom.SetIsStopMoveCar(true);
                            return;
                        }
                        //Debug.Log("Unity:"+"progressNum "+progressNum);
                    }
                }

                // determine the position we should currently be aiming for
                // (this is different to the current progress position, it is a a certain amount ahead along the route)
                // we use lerp as a simple way of smoothing out the speed over time.
                if (Time.deltaTime > 0)
                {
                    speed = Mathf.Lerp(speed, (lastPosition - transform.position).magnitude / Time.deltaTime,
                                       Time.deltaTime);
                }
                target.position =
                    circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor * speed)
                    .position;
                target.rotation =
                    Quaternion.LookRotation(
                        circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor * speed)
                        .direction);


                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude * 0.5f;
                }

                lastPosition = transform.position;
            }
            else
            {
                // point to point mode. Just increase the waypoint if we're close enough:

                Vector3 targetDelta = target.position - transform.position;
                if (targetDelta.magnitude < pointToPointThreshold)
                {
                    progressNum = (progressNum + 1) % circuit.Waypoints.Length;
                }

                target.position = circuit.Waypoints[progressNum].position;
                target.rotation = circuit.Waypoints[progressNum].rotation;

                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude;
                }
                lastPosition = transform.position;
            }
        }
Ejemplo n.º 6
0
        private void Update()
        {
            float driveAxis = CrossPlatformInputManager.GetAxis("Vertical");

            if (driveAxis < 0 && lookAheadForTargetOffset > 0.0f)
            {
                lookAheadForTargetOffset += (driveAxis * 0.003f);
            }
            else if (driveAxis > 0 && lookAheadForTargetOffset < 1.1f)
            {
                lookAheadForTargetOffset += (driveAxis * 0.002f);
            }


            if (Input.GetButton("Fire2") && lookAheadForTargetOffset < 1.1f)
            {
                Debug.Log(Input.mousePosition);

                lookAheadForTargetOffset += 0.002f;
            }
            if (Input.GetButton("Fire1") && lookAheadForTargetOffset > 0.0f)
            {
                lookAheadForTargetOffset -= 0.003f;
            }
            else if (lookAheadForTargetOffset < 0.0f)
            {
                lookAheadForTargetOffset = 0.0f;
            }

            if (lookAheadForTargetOffset > 0.03f)
            {
                lookAheadForTargetOffset -= (lookAheadForTargetOffset * 0.0025f);
            }

            if (progressStyle == ProgressStyle.SmoothAlongRoute)
            {
                // determine the position we should currently be aiming for
                // (this is different to the current progress position, it is a a certain amount ahead along the route)
                // we use lerp as a simple way of smoothing out the speed over time.
                if (Time.deltaTime > 0)
                {
                    speed = Mathf.Lerp(speed, (lastPosition - transform.position).magnitude / Time.deltaTime,
                                       Time.deltaTime);
                }
                target.position =
                    circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor * speed)
                    .position;
                target.rotation =
                    Quaternion.LookRotation(
                        circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor * speed)
                        .direction);


                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude * 0.5f;
                }

                lastPosition = transform.position;
            }
            else
            {
                // point to point mode. Just increase the waypoint if we're close enough:

                Vector3 targetDelta = target.position - transform.position;
                if (targetDelta.magnitude < pointToPointThreshold)
                {
                    progressNum = (progressNum + 1) % circuit.Waypoints.Length;
                }


                target.position = circuit.Waypoints[progressNum].position;
                target.rotation = circuit.Waypoints[progressNum].rotation;

                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude;
                }
                lastPosition = transform.position;
            }
        }
Ejemplo n.º 7
0
        private void Update()
        {
            if (progressStyle == ProgressStyle.SmoothAlongRoute)
            {
                // determine the position we should currently be aiming for
                // (this is different to the current progress position, it is a a certain amount ahead along the route)
                // we use lerp as a simple way of smoothing out the speed over time.
                if (Time.deltaTime > 0)
                {
                    speed = Mathf.Lerp(speed, (lastPosition - transform.position).magnitude/Time.deltaTime,
                                       Time.deltaTime);
                }
                target.position =
                    circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor*speed)
                           .position;
                target.rotation =
                    Quaternion.LookRotation(
                        circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor*speed)
                               .direction);


                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude*0.5f;
                }

                lastPosition = transform.position;
            }
            else
            {
                // point to point mode. Just increase the waypoint if we're close enough:

                Vector3 targetDelta = target.position - transform.position;
                if (targetDelta.magnitude < pointToPointThreshold)
                {
                    progressNum = (progressNum + 1)%circuit.Waypoints.Length;
                }


                target.position = circuit.Waypoints[progressNum].position;
                target.rotation = circuit.Waypoints[progressNum].rotation;

                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude;
                }
                lastPosition = transform.position;
            }
        }
        private void Update()
        {
            if (progressStyle == ProgressStyle.SmoothAlongRoute)
            {
                // 平滑路径点模式

                // 确定我们应当瞄准的位置
                // 这与当前的进度位置不同,这是两个路近的中间量
                // 我们使用插值来简单地平滑速度
                // determine the position we should currently be aiming for
                // (this is different to the current progress position, it is a a certain amount ahead along the route)
                // we use lerp as a simple way of smoothing out the speed over time.
                if (Time.deltaTime > 0)
                {
                    speed = Mathf.Lerp(speed, (lastPosition - transform.position).magnitude / Time.deltaTime,
                                       Time.deltaTime);
                }
                // 根据路程向前偏移一定距离,获取路径点
                target.position =
                    circuit.GetRoutePoint(progressDistance + lookAheadForTargetOffset + lookAheadForTargetFactor * speed)
                    .position;
                // 路径点方向调整。这里重复计算了,为什么不缓存?
                target.rotation =
                    Quaternion.LookRotation(
                        circuit.GetRoutePoint(progressDistance + lookAheadForSpeedOffset + lookAheadForSpeedFactor * speed)
                        .direction);

                // 获取未偏移的路径点
                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                // 车辆的移动超过路径点的话,将路径点前移
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude * 0.5f;
                }

                // 记录位置
                lastPosition = transform.position;
            }
            else
            {
                // 点对点模式,如果足够近的话就增加路程
                // point to point mode. Just increase the waypoint if we're close enough:

                // 距离小于阈值,就将路径点移动到下一个
                Vector3 targetDelta = target.position - transform.position;
                if (targetDelta.magnitude < pointToPointThreshold)
                {
                    progressNum = (progressNum + 1) % circuit.Waypoints.Length;
                }

                // 设置路径对象的位置和旋转方向
                target.position = circuit.Waypoints[progressNum].position;
                target.rotation = circuit.Waypoints[progressNum].rotation;

                // 同平滑路径点模式一样进行路程计算
                // get our current progress along the route
                progressPoint = circuit.GetRoutePoint(progressDistance);
                Vector3 progressDelta = progressPoint.position - transform.position;
                if (Vector3.Dot(progressDelta, progressPoint.direction) < 0)
                {
                    progressDistance += progressDelta.magnitude;
                }
                lastPosition = transform.position;
            }
        }