/// <summary>
        /// Setup the area
        /// </summary>
        private void Start()
        {
            // Create checkpoints along the race path
            Debug.Assert(racePath != null, "Race path was not set");
            Checkpoints = new List <GameObject>();
            int numCheckpoints = (int)racePath.MaxUnit(CinemachinePathBase.PositionUnits.PathUnits);

            for (int i = 0; i < numCheckpoints; i++)
            {
                // Instantiate either checkpoint or finish line checkpoint
                GameObject checkPoint;
                if (i == numCheckpoints - 1)
                {
                    checkPoint = Instantiate <GameObject>(finishCheckPointPrefab);
                }
                else
                {
                    checkPoint = Instantiate <GameObject>(checkPointPrefab);
                }

                // Set the parent, position and rotation
                checkPoint.transform.SetParent(racePath.transform);
                checkPoint.transform.localPosition = racePath.m_Waypoints[i].position;
                checkPoint.transform.rotation      = racePath.EvaluateOrientationAtUnit(i, CinemachinePathBase.PositionUnits.PathUnits);

                // Add checkpoint to list
                Checkpoints.Add(checkPoint);
            }
        }
Exemplo n.º 2
0
    private void Orient()
    {
        Quaternion orientation = path.EvaluateOrientationAtUnit(dolly.m_Position, dolly.m_PositionUnits);
        var        diffZ       = orientation.eulerAngles.z - shipModel.rotation.eulerAngles.z;
        Quaternion rot         = Quaternion.AngleAxis(diffZ, shipModel.forward);

        shipModel.rotation = rot * shipModel.rotation;
    }
Exemplo n.º 3
0
    private void TurnSpeedModifier()
    {
        float3 startPosition = m_Path.EvaluatePositionAtUnit(m_DollyCart.m_Position, m_DollyCart.m_PositionUnits);
        float3 startTangent  = math.mul(m_Path.EvaluateOrientationAtUnit(m_DollyCart.m_Position, m_DollyCart.m_PositionUnits), c_XZPLANE);
        float3 prevTangent   = startTangent;
        float3 nextTangent   = float3.zero;

        float dotAverage = 0.0f;
        int   count      = 0;
        bool  turnRight  = false;

        for (int i = 1; i <= m_TurnSamplePositionCount; ++i)
        {
            nextTangent = math.mul(m_Path.EvaluateOrientationAtUnit(m_DollyCart.m_Position + (i * m_TurnLookAheadPathDistance), m_DollyCart.m_PositionUnits), c_XZPLANE);

            if (i == 1)
            {
                turnRight = math.cross(startTangent, nextTangent).y < 0 ? true : false;
            }

            if (math.cross(prevTangent, nextTangent).y > 0 && turnRight)
            {
                break;
            }

            dotAverage += math.dot(math.normalizesafe(prevTangent), math.normalizesafe(nextTangent)) * (1 - ((1 / m_TurnSamplePositionCount) * i));
            ++count;
        }

        dotAverage /= count;
        dotAverage  = math.clamp(dotAverage, 0, 1);

        m_TargetTurnSpeed = math.clamp(1 - ((1 - dotAverage) * m_MaxTurnSpeedModifier), 0, 1);

        if (math.distance(m_CurrentTurnSpeed, m_TargetTurnSpeed) < 0.01f)
        {
            m_TargetTurnSpeed = m_CurrentTurnSpeed;
        }

        if (m_CurrentTurnSpeed != m_TargetTurnSpeed)
        {
            m_CurrentTurnSpeed = m_CurrentTurnSpeed + (m_CurrentTurnSpeed < m_TargetTurnSpeed ? m_TurnAcceleration : -m_TurnBreakForce);
        }

        m_CurrentTurnSpeed = math.clamp(m_CurrentTurnSpeed, 0, 1);
    }
 /// <summary>
 /// 设置位于曲线的位置
 /// </summary>
 /// <param name="trans"></param>
 /// <param name="distanceAlongPath"></param>
 void SetCartPosition(Transform trans, CinemachineSmoothPath path, float distanceAlongPath)
 {
     if (path != null)
     {
         float m_Position;
         m_Position     = path.StandardizeUnit(distanceAlongPath, m_PositionUnits);
         trans.position = path.EvaluatePositionAtUnit(m_Position, m_PositionUnits);
         trans.rotation = path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits);
     }
 }
Exemplo n.º 5
0
    void SetCartPosition(float distanceAlongPath)
    {
        if (m_Path != null)
        {
            m_Position = m_Path.StandardizeUnit(distanceAlongPath, m_PositionUnits);
            Vector3 pos = m_Path.EvaluatePositionAtUnit(m_Position, m_PositionUnits);
            transform.position = new Vector3(pos.x, pos.y, pos.z);

            //transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, m_Path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits).eulerAngles.y, transform.rotation.eulerAngles.z);
            transform.rotation = m_Path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits);
        }
    }
Exemplo n.º 6
0
    void Start()
    {
        checkpoints = new List <GameObject>();
        int NoCheckpoints = (int)racePath.MaxUnit(CinemachinePathBase.PositionUnits.PathUnits);

        for (int i = 0; i < NoCheckpoints; i++)
        {
            GameObject checkpoint = Instantiate <GameObject>(checkPointPrefab);

            if (i == NoCheckpoints - 1)
            {
                checkpoint.tag = "finalCheckpoint";
            }

            checkpoint.transform.SetParent(racePath.transform);
            checkpoint.transform.localPosition = racePath.m_Waypoints[i].position;
            checkpoint.transform.rotation      = racePath.EvaluateOrientationAtUnit(i, CinemachinePathBase.PositionUnits.PathUnits);

            checkpoints.Add(checkpoint);
        }
    }
Exemplo n.º 7
0
    private void Start()
    {
        Debug.Assert(racePath != null, "Racepath was not set");
        Checkpoints = new List <GameObject>();
        int numCheckpoints = (int)racePath.MaxUnit(CinemachinePathBase.PositionUnits.PathUnits);

        for (int i = 0; i < numCheckpoints; i++)
        {
            GameObject checkpoint;
            if (i == numCheckpoints - 1)
            {
                checkpoint = Instantiate <GameObject>(finishCheckpointprefab);
            }
            else
            {
                checkpoint = Instantiate <GameObject>(checkpointprefab);
            }
            checkpoint.transform.SetParent(racePath.transform);
            checkpoint.transform.localPosition = racePath.m_Waypoints[i].position;
            checkpoint.transform.localRotation = racePath.EvaluateOrientationAtUnit(i, CinemachinePathBase.PositionUnits.PathUnits);
            Checkpoints.Add(checkpoint);
        }
    }