Ejemplo n.º 1
0
    private void LateUpdate()
    {
        if (!followPlayer)
        {
            return;
        }
        float nearestPercent = gameplayPath.GetNearestPoint(player.position, false);
        float theta          = nearestPercent - lastPercent;

        if (theta > 0.5f)
        {
            lastPercent += 1;
        }
        else if (theta < -0.5f)
        {
            lastPercent += -1;
        }

        float usePercent = Mathf.Lerp(lastPercent, nearestPercent, 0.4f);

        lastPercent = usePercent;
        Vector3 nearestPoint = gameplayPath.GetPathPosition(usePercent, false);

        targetCamera.position = Vector3.Lerp(targetCamera.position, nearestPoint, 0.4f);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 场景自定义的摄像机跟随路线
    /// </summary>
    /// <param name="lookPos"></param>
    private void UpdateFollowCamera(Vector3 lookPos)
    {
        float nearestPercent = mFollowPath.GetNearestPoint(lookPos);
        float usePercent     = Mathf.Lerp(lastPercent, nearestPercent, 0.4f);

        lastPercent = usePercent;
        Vector3 nearestPoint = mFollowPath.GetPathPosition(usePercent, true) + mFollowPath.transform.position;


        mCameraTransform.position = Vector3.Lerp(mCameraTransform.position, nearestPoint, 0.4f);

        Quaternion lookRotation = Quaternion.LookRotation(lookPos - mCameraTransform.position);

        mCameraTransform.rotation = Quaternion.Slerp(mCameraTransform.rotation, lookRotation, 0.4f);
    }
Ejemplo n.º 3
0
    //Set the initial position of the cam so we don't jump at the start of the demo
    void Start()
    {
        float nearestPercent = path.GetNearestPoint(player.position, ignoreNormalise, 5);

        lastPercent = nearestPercent;

        Vector3 nearestPoint = path.GetPathPosition(nearestPercent, ignoreNormalise);

        cam.position = nearestPoint;
        switch (_orientationMode)
        {
        case OrientationModes.none:
            //none
            break;

        case OrientationModes.lookAtTarget:
            cam.rotation = Quaternion.LookRotation(player.position - cam.position);
            break;

        case OrientationModes.lookAtPathDirection:
            cam.rotation = Quaternion.LookRotation(path.GetPathDirection(nearestPercent));
            break;
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Retrieve the animation orientation at a percent based on the animation mode
    /// </summary>
    /// <param name="percent">Path Percent 0-1</param>
    /// <param name="ignoreNormalisation">Should the percetage be normalised</param>
    /// <returns>A rotation</returns>
    public Quaternion GetAnimatedOrientation(float percent, bool ignoreNormalisation)
    {
        Quaternion output = Quaternion.identity;
        Vector3    currentPosition, forward;

//        bool isStill = animationMode == animationModes.still;
        switch (orientationMode)
        {
        case orientationModes.custom:
            output = cameraPath.GetPathRotation(percent, ignoreNormalisation);
            break;

        case orientationModes.target:
            currentPosition = cameraPath.GetPathPosition(percent);
            if (orientationTarget != null)
            {
                forward = orientationTarget.transform.position - currentPosition;
            }
            else
            {
                forward = Vector3.forward;
            }
            output = Quaternion.LookRotation(forward, targetModeUp);
            break;

        case orientationModes.followpath:
            output  = Quaternion.LookRotation(cameraPath.GetPathDirection(percent));
            output *= Quaternion.Euler(transform.forward * -cameraPath.GetPathTilt(percent));
            break;

        case orientationModes.reverseFollowpath:
            output  = Quaternion.LookRotation(-cameraPath.GetPathDirection(percent));
            output *= Quaternion.Euler(transform.forward * -cameraPath.GetPathTilt(percent));
            break;

        case orientationModes.mouselook:
            if (!Application.isPlaying)
            {
                output  = Quaternion.LookRotation(cameraPath.GetPathDirection(percent));
                output *= Quaternion.Euler(transform.forward * -cameraPath.GetPathTilt(percent));
            }
            else
            {
                //                    output = GetMouseLook();
                output  = Quaternion.LookRotation(cameraPath.GetPathDirection(percent));
                output *= GetMouseLook();
            }
            break;

        case orientationModes.followTransform:
            if (orientationTarget == null)
            {
                return(Quaternion.identity);
            }
            float nearestPerc = cameraPath.GetNearestPoint(orientationTarget.position);
            nearestPerc     = Mathf.Clamp01(nearestPerc + nearestOffset);
            currentPosition = cameraPath.GetPathPosition(nearestPerc);
            forward         = orientationTarget.transform.position - currentPosition;
            output          = Quaternion.LookRotation(forward);
            break;

        case orientationModes.twoDimentions:
            output = Quaternion.LookRotation(Vector3.forward);
            break;

        case orientationModes.fixedOrientation:
            output = Quaternion.LookRotation(fixedOrientaion);
            break;

        case orientationModes.none:
            output = animationObject.rotation;
            break;
        }

        output *= transform.rotation;

        return(output);
    }