Example #1
0
        void ClampSystems()
        {
            for (fx = 0; fx < fxObjects.Length; fx++)
            {
                if (fxObjects[fx] != null)
                {
                    if (clampIndex[fx] != 0)
                    {
                        currPXWaterPos = 0.0f;

                        //get particles
                        useParticleComponent = fxParticles[fx];
                        if (setParticles == null)
                        {
                            setParticles = new ParticleSystem.Particle[useParticleComponent.particleCount];
                        }
                        useParticleComponent.GetParticles(setParticles);
                        //set particles
                        if (useParticleComponent.particleCount > 0.0f)
                        {
                            for (px = 0; px < useParticleComponent.particleCount; px++)
                            {
                                currPXWaterPos = moduleObject.SuimonoGetHeight(setParticles[px].position, "surfaceLevel");

                                //Clamp to Surface
                                if (clampIndex[fx] == 1)
                                {
                                    setParticles[px].position = new Vector3(setParticles[px].position.x, currPXWaterPos + 0.2f, setParticles[px].position.z);
                                }
                                //Clamp Under Water
                                if (clampIndex[fx] == 2)
                                {
                                    if (setParticles[px].position.y > currPXWaterPos - 0.2f)
                                    {
                                        setParticles[px].position = new Vector3(setParticles[px].position.x, currPXWaterPos - 0.2f, setParticles[px].position.z);
                                    }
                                }
                                //Clamp Above Water
                                if (clampIndex[fx] == 3)
                                {
                                    if (setParticles[px].position.y < currPXWaterPos + 0.2f)
                                    {
                                        setParticles[px].position = new Vector3(setParticles[px].position.x, currPXWaterPos + 0.2f, setParticles[px].position.z);
                                    }
                                }
                            }
                            useParticleComponent.SetParticles(setParticles, setParticles.Length);
                            useParticleComponent.Play();
                        }
                    }
                }
            }
        }
    void FixedUpdate()
    {
        if (isActive)
        {
            //------------------------------------
            //  GET DATA FROM MASTER CONTROLLER
            //------------------------------------
            cameraObject = MC.cameraObject;


            //---------------------------------
            //  GET KEYBOARD AND MOUSE INPUTS
            //---------------------------------
            if (isControllable)
            {
                //RESET MOVEMENT
                moveForward  = 0.0f;
                moveSideways = 0.0f;
                //moveVert = 0.0f;

                // GET WASD MOVEMENT KEYS
                if (IC.inputKeyW)
                {
                    moveForward = 1.0f;
                }
                if (IC.inputKeyS)
                {
                    moveForward = -1.0f;
                }
                if (IC.inputKeyA)
                {
                    moveSideways = -1.0f;
                }
                if (IC.inputKeyD)
                {
                    moveSideways = 1.0f;
                }
                //if (IC.inputKeyQ) moveVert = -1.0f;
                //if (IC.inputKeyE) moveVert = 1.0f;

                //MOUSE BUTTON 0
                //isMouseMove = IC.inputMouseKey0;

                //MOUSE BUTTON 1
                isExtraZoom = IC.inputMouseKey1;
                if (isExtraZoom)
                {
                    setFOV = 0.5f;
                }
                else
                {
                    setFOV = 1.0f;
                }

                //SHIFT RUN/SPRINT
                // Tap Shift to toggle
                // hold shift to sprint
                isWalking = false;
                if (moveForward != 0.0f || moveSideways != 0.0f)
                {
                    isWalking = true;
                }
                if (IC.inputKeySHIFTL)
                {
                    runButtonTime += Time.deltaTime;
                    if (runButtonTime > 0.2f)
                    {
                        isSprinting = true;
                    }
                }
                else
                {
                    if (runButtonTime > 0.0f)
                    {
                        if (runButtonTime < 0.2f)
                        {
                            isRunning = !isRunning;
                            if (isRunning)
                            {
                                toggleRun = true;
                            }
                        }
                        if (runButtonTime > 0.2f)
                        {
                            isRunning = false;
                        }
                    }
                    if (isSprinting && toggleRun)
                    {
                        isRunning = true;
                    }
                    isSprinting   = false;
                    runButtonTime = 0.0f;
                }


                //SPACE
                if (Input.mousePosition.x > 325f || Input.mousePosition.y < 265f)
                {
                    orbitView = IC.inputMouseKey0 || IC.inputMouseKey1;
                }
                else
                {
                    orbitView         = false;
                    IC.inputMouseKey0 = false;
                    IC.inputMouseKey1 = false;
                }
            }


            //CHECK FOR MOUSE INPUT
            targetPosition   = cameraTarget.position;
            oldMouseRotation = MouseRotationDistance;
            //oldMouseVRotation = MouseVerticalDistance;

            //GET MOUSE MOVEMENT
            MouseRotationDistance = IC.inputMouseX;
            MouseVerticalDistance = IC.inputMouseY;
            MouseScrollDistance   = IC.inputMouseWheel;
            if (reverseXAxis)
            {
                MouseRotationDistance = -IC.inputMouseX;
            }
            if (reverseYAxis)
            {
                MouseVerticalDistance = -IC.inputMouseY;
            }



            //---------------------------------
            //  HANDLE CAMERA VIEWS
            //---------------------------------
            if (!isControllable)
            {
                //Zoom Settings used for the intro screen
                camFOV         = 63.2f;
                followLat      = Mathf.Lerp(followLat, -0.85f, Time.deltaTime * 4.0f);
                followHeight   = Mathf.Lerp(followHeight, 1.8f, Time.deltaTime * 4.0f);
                followDistance = Mathf.Lerp(followDistance, 5.0f, Time.deltaTime * 4.0f);

                axisSensitivity = new Vector2(
                    Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f),
                    Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f)
                    );

                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;
            }

            //IDLE SETTINGS lerp camera back
            camFOV       = Mathf.Lerp(camFOV, cameraFOV * setFOV, Time.deltaTime * 4.0f);
            followLat    = Mathf.Lerp(followLat, -0.4f, Time.deltaTime * 4.0f);
            followHeight = Mathf.Lerp(followHeight, 1.4f, Time.deltaTime * 2.0f);

            axisSensitivity = new Vector2(
                Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f),
                Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f)
                );

            //LOCK CURSOR
            Cursor.lockState = CursorLockMode.None;



            //---------------------------------
            //  SUIMONO SPECIFIC HANDLING
            //---------------------------------
            // we use this to get the current Suimono plane water level (if applicable) from the
            // main Suimono Module object, then translate this into different walk / run speeds
            // based on water depth.
            //var waterLevel : float = suimonoModuleObject.GetWaterDepth(cameraTarget);
            if (suimonoModuleObject != null)
            {
                float waterLevel = suimonoModuleObject.SuimonoGetHeight(cameraTarget.position, "object depth");


                isInWater = false;

                if (waterLevel < 0.0f)
                {
                    waterLevel = 0.0f;
                }
                if (waterLevel > 0.0f)
                {
                    isInWater     = true;
                    isInWaterDeep = false;
                    isUnderWater  = false;

                    if (waterLevel >= 0.9f && waterLevel < 1.8f)
                    {
                        isInWaterDeep = true;
                    }
                    if (waterLevel >= 1.8f)
                    {
                        isUnderWater = true;
                    }
                }
            }



            if (isControllable)
            {
                //---------------------------------
                //  CAMERA POSITIONING
                //---------------------------------

                //Calculate Follow Distance
                float followLerpSpeed = 2.0f;
                followDistance   -= (MouseScrollDistance * 20.0f);
                followDistance    = Mathf.Clamp(followDistance, minZoomAmount, maxZoomAmount);
                followTgtDistance = Mathf.Lerp(followTgtDistance, followDistance, Time.deltaTime * followLerpSpeed);

                // Calculate Rotation
                if (orbitView)
                {
                    camRotation = Mathf.Lerp(oldMouseRotation, MouseRotationDistance * axisSensitivity.x, Time.deltaTime);
                }

                targetRotation.eulerAngles = new Vector3(
                    targetRotation.eulerAngles.x,
                    (targetRotation.eulerAngles.y + camRotation),
                    targetRotation.eulerAngles.z
                    );

                cameraObject.transform.eulerAngles = new Vector3(
                    targetRotation.eulerAngles.x,
                    targetRotation.eulerAngles.y,
                    cameraObject.transform.eulerAngles.z
                    );

                if (orbitView)
                {
                    camHeight = Mathf.Lerp(camHeight, camHeight + MouseVerticalDistance * axisSensitivity.y, Time.deltaTime);
                }
                camHeight = Mathf.Clamp(camHeight, -45.0f, 45.0f);

                // SET CAMERA POSITION and ROTATIONS
                cameraObject.transform.position = new Vector3(
                    cameraTarget.transform.position.x + cameraOffset.x + (-cameraObject.transform.up.x * followTgtDistance),
                    Mathf.Lerp(camHeight, cameraTarget.transform.position.y + cameraOffset.y + (-cameraObject.transform.up.y * followTgtDistance), Time.deltaTime * 0.5f),
                    cameraTarget.transform.position.z + cameraOffset.z + (-cameraObject.transform.up.z * followTgtDistance)
                    );

                cameraObject.transform.LookAt(new Vector3(targetPosition.x, targetPosition.y + followHeight, targetPosition.z));
            }


            //---------------------------------
            //  SET CAMERA SETTINGS and FX
            //---------------------------------
            if (isControllable)
            {
                //SET CAMERA SETTINGS
                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;
            }
        }


        //------------------------------------
        //  SEND MODES TO CHARACTER ANIMATOR
        //------------------------------------
        if (targetAnimator != null)
        {
            targetAnimator.isWalking    = isWalking;
            targetAnimator.isRunning    = isRunning;
            targetAnimator.isSprinting  = isSprinting;
            targetAnimator.moveForward  = moveForward;
            targetAnimator.moveSideways = moveSideways;

            targetAnimator.gSlope        = gSlope;
            targetAnimator.useSlope      = useSlope;
            targetAnimator.isInWater     = isInWater;
            targetAnimator.isInWaterDeep = isInWaterDeep;
            targetAnimator.isUnderWater  = isUnderWater;
        }
    }
    void FixedUpdate()
    {
        if (isActive)
        {
            //------------------------------------
            //  GET DATA FROM MASTER CONTROLLER
            //------------------------------------
            cameraObject = MC.cameraObject;


            //---------------------------------
            //  GET KEYBOARD AND MOUSE INPUTS
            //---------------------------------

            if (isControllable)
            {
                //RESET MOVEMENT
                moveForward  = 0.0f;
                moveSideways = 0.0f;
                moveVert     = 0.0f;

                // GET WASD MOVEMENT KEYS
                if (IC.inputKeyW)
                {
                    moveForward = 1.0f;
                }
                if (IC.inputKeyS)
                {
                    moveForward = -1.0f;
                }
                if (IC.inputKeyA)
                {
                    moveSideways = -1.0f;
                }
                if (IC.inputKeyD)
                {
                    moveSideways = 1.0f;
                }
                if (IC.inputKeyQ)
                {
                    moveVert = -1.0f;
                }
                if (IC.inputKeyE)
                {
                    moveVert = 1.0f;
                }

                //MOUSE BUTTON 0
                //isMouseMove = IC.inputMouseKey0;

                //MOUSE BUTTON 1
                isExtraZoom = IC.inputMouseKey1;
                if (isExtraZoom)
                {
                    setFOV = 0.5f;
                }
                else
                {
                    setFOV = 1.0f;
                }

                //SHIFT RUN/SPRINT
                // Tap Shift to toggle
                // hold shift to sprint
                isWalking = false;
                if (moveForward != 0.0f || moveSideways != 0.0f)
                {
                    isWalking = true;
                }
                if (IC.inputKeySHIFTL)
                {
                    runButtonTime += Time.deltaTime;
                    if (runButtonTime > 0.2f)
                    {
                        isSprinting = true;
                    }
                }
                else
                {
                    if (runButtonTime > 0.0f)
                    {
                        if (runButtonTime < 0.2f)
                        {
                            isRunning = !isRunning;
                            if (isRunning)
                            {
                                toggleRun = true;
                            }
                        }
                        if (runButtonTime > 0.2f)
                        {
                            isRunning = false;
                        }
                    }
                    if (isSprinting && toggleRun)
                    {
                        isRunning = true;
                    }
                    isSprinting   = false;
                    runButtonTime = 0.0f;
                }

                //SPACE
                orbitView = IC.inputKeySPACE;
            }

            //CHECK FOR MOUSE INPUT
            targetPosition   = cameraTarget.position;
            oldMouseRotation = MouseRotationDistance;
            //oldMouseVRotation = MouseVerticalDistance;

            //GET MOUSE MOVEMENT
            MouseRotationDistance = IC.inputMouseX;
            MouseVerticalDistance = IC.inputMouseY;
            MouseScrollDistance   = IC.inputMouseWheel;
            if (reverseXAxis)
            {
                MouseRotationDistance = -IC.inputMouseX;
            }
            if (reverseYAxis)
            {
                MouseVerticalDistance = -IC.inputMouseY;
            }



            //---------------------------------
            //  HANDLE CAMERA VIEWS
            //---------------------------------
            if (!isControllable)
            {
                //Zoom Settings used for the intro screen
                camFOV         = 63.2f;
                followLat      = Mathf.Lerp(followLat, -0.85f, Time.deltaTime * 4.0f);
                followHeight   = Mathf.Lerp(followHeight, 1.8f, Time.deltaTime * 4.0f);
                followDistance = Mathf.Lerp(followDistance, 5.0f, Time.deltaTime * 4.0f);

                axisSensitivity = new Vector2(
                    Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f),
                    Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f)
                    );

                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;
            }

            //IDLE SETTINGS lerp camera back
            camFOV       = Mathf.Lerp(camFOV, cameraFOV * setFOV, Time.deltaTime * 4.0f);
            followLat    = Mathf.Lerp(followLat, -0.4f, Time.deltaTime * 4.0f);
            followHeight = Mathf.Lerp(followHeight, 1.4f, Time.deltaTime * 2.0f);

            axisSensitivity = new Vector2(
                Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f),
                Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f)
                );

            //LOCK CURSOR
            Cursor.lockState = CursorLockMode.None;



            //---------------------------------
            //  SUIMONO SPECIFIC HANDLING
            //---------------------------------
            // we use this to get the current Suimono plane water level (if applicable) from the
            // main Suimono Module object, then translate this into different walk / run speeds
            // based on water depth.
            if (suimonoModuleObject != null)
            {
                float waterLevel = suimonoModuleObject.SuimonoGetHeight(cameraTarget.position, "object depth");

                isInWater = false;

                if (waterLevel < 0.0f)
                {
                    waterLevel = 0.0f;
                }
                if (waterLevel > 0.0f)
                {
                    isInWater     = true;
                    isInWaterDeep = false;
                    isUnderWater  = false;
                    isFloating    = false;
                    isAtSurface   = false;

                    if (waterLevel >= 0.9f && waterLevel < 1.8f)
                    {
                        isInWaterDeep = true;
                    }
                    if (waterLevel >= 1.8f)
                    {
                        isUnderWater = true;
                    }
                    if (waterLevel >= 1.2f && waterLevel < 1.8f)
                    {
                        isAtSurface = true;
                    }
                    if (isInWaterDeep && waterLevel > 2.0f)
                    {
                        isFloating = true;
                    }
                }

                //turn off buoyancy when underwater (if object exists)
                if (isUnderWater)
                {
                    if (buoyancyObject != null)
                    {
                        buoyancyObject.engageBuoyancy = false;
                    }
                }
                else
                {
                    if (buoyancyObject != null)
                    {
                        buoyancyObject.engageBuoyancy = true;
                    }
                }
            }



            if (isControllable)
            {
                //---------------------------------
                //  CHARACTER ROTATION
                //---------------------------------

                //ROTATE CHARACTER
                if (!orbitView)
                {
                    //calculate rotation sensitivity
                    rotSense = rotationSensitivity;
                    if (isSprinting)
                    {
                        rotSense *= 2.0f;
                    }

                    //calculate rotation  3-360 hedge
                    float rotH = 0.0f;
                    float tgt  = 0.0f;

                    //move forward
                    if (moveForward == 1.0f && moveSideways == 0.0f)
                    {
                        tgt = cameraObject.transform.eulerAngles.y;
                        if ((cameraTarget.eulerAngles.y - tgt) > 180.0f)
                        {
                            rotH = -360.0f;
                        }
                        if ((cameraTarget.eulerAngles.y - tgt) < -180.0f)
                        {
                            rotH = 360.0f;
                        }
                        cameraTarget.eulerAngles = new Vector3(
                            cameraTarget.eulerAngles.x,
                            Mathf.Lerp(cameraTarget.eulerAngles.y + rotH, tgt, Time.deltaTime * rotSense),
                            cameraTarget.eulerAngles.z
                            );

                        //move backward
                    }
                    else if (moveForward == -1.0f && moveSideways == 0.0f)
                    {
                        rotSense *= 1.0f;
                        tgt       = cameraObject.transform.eulerAngles.y - 180.0f;
                        if ((cameraTarget.eulerAngles.y - tgt) > 180.0f)
                        {
                            rotH = -360.0f;
                        }
                        if ((cameraTarget.eulerAngles.y - tgt) < -180.0f)
                        {
                            rotH = 360.0f;
                        }
                        cameraTarget.eulerAngles = new Vector3(
                            cameraTarget.eulerAngles.x,
                            Mathf.Lerp(cameraTarget.eulerAngles.y + rotH, tgt, Time.deltaTime * rotSense),
                            cameraTarget.eulerAngles.z
                            );

                        //move sideways
                    }
                    else if (moveSideways != 0.0f && moveForward == 0.0f)
                    {
                        tgt = cameraObject.transform.eulerAngles.y + (90f * moveSideways);
                        if ((cameraTarget.eulerAngles.y - tgt) > 180.0f)
                        {
                            rotH = -360.0f;
                        }
                        if ((cameraTarget.eulerAngles.y - tgt) < -180.0f)
                        {
                            rotH = 360.0f;
                        }
                        cameraTarget.eulerAngles = new Vector3(
                            cameraTarget.eulerAngles.x,
                            Mathf.Lerp(cameraTarget.eulerAngles.y + rotH, tgt, Time.deltaTime * rotSense),
                            cameraTarget.eulerAngles.z
                            );

                        //move forward side
                    }
                    else if (moveSideways != 0.0f && moveForward == 1.0f)
                    {
                        rotSense *= 1.4f;
                        tgt       = cameraObject.transform.eulerAngles.y + (45f * moveSideways);
                        if ((cameraTarget.eulerAngles.y - tgt) > 180.0f)
                        {
                            rotH = -360.0f;
                        }
                        if ((cameraTarget.eulerAngles.y - tgt) < -180.0f)
                        {
                            rotH = 360.0f;
                        }
                        cameraTarget.eulerAngles = new Vector3(
                            cameraTarget.eulerAngles.x,
                            Mathf.Lerp(cameraTarget.eulerAngles.y + rotH, tgt, Time.deltaTime * rotSense),
                            cameraTarget.eulerAngles.z
                            );

                        //move backward side
                    }
                    else if (moveSideways != 0.0f && moveForward == -1.0f)
                    {
                        rotSense *= 1.4f;
                        tgt       = cameraObject.transform.eulerAngles.y - 180.0f - (45f * moveSideways);
                        if ((cameraTarget.eulerAngles.y - tgt) > 180.0f)
                        {
                            rotH = 360.0f;
                        }
                        if ((cameraTarget.eulerAngles.y - tgt) < -180.0f)
                        {
                            rotH = -360.0f;
                        }
                        cameraTarget.eulerAngles = new Vector3(
                            cameraTarget.eulerAngles.x,
                            Mathf.Lerp(cameraTarget.eulerAngles.y - rotH, tgt, Time.deltaTime * rotSense),
                            cameraTarget.eulerAngles.z
                            );
                    }
                    else
                    {
                        xMove = Mathf.Lerp(xMove, 0.0f, Time.deltaTime);
                    }

                    cameraTarget.eulerAngles = new Vector3(0.0f, cameraTarget.eulerAngles.y, 0.0f);
                }



                //---------------------------------
                // CALCULATE GROUND SLOPE
                //---------------------------------
                gSlope   = 0.0f;
                useSlope = 0.0f;
                Vector3    startPos = cameraTarget.position + new Vector3(0f, 1.0f, 0f);
                Vector3    endPos   = cameraTarget.position + new Vector3(0f, -0.25f, 0f);
                RaycastHit hitA;
                RaycastHit hitB;

                if (Physics.Linecast(startPos, endPos, out hitA))
                {
                    if (hitA.transform != cameraTarget.transform)
                    {
                        if (showDebug)
                        {
                            Debug.DrawLine(startPos, endPos, Color.red);
                        }

                        if (Physics.Linecast(startPos + (cameraTarget.forward * 0.25f), endPos + (cameraTarget.forward * 0.25f), out hitB))
                        {
                            if (showDebug)
                            {
                                Debug.DrawLine(startPos + (cameraTarget.forward * 0.25f), endPos + (cameraTarget.forward * 0.25f), Color.green);
                            }
                            if (showDebug)
                            {
                                Debug.DrawLine(hitA.point, hitB.point, Color.black);
                            }

                            //calculate angle
                            float aFac1 = (hitB.point.y - hitA.point.y);
                            float aFac2 = (hitB.point.x - hitA.point.x);
                            gSlope   = (Mathf.Atan2(aFac1, aFac2) * Mathf.Rad2Deg);
                            useSlope = gSlope;
                            if (gSlope < 0.0f)
                            {
                                useSlope = 90.0f + ((Mathf.Atan2(aFac1, aFac2) * Mathf.Rad2Deg) % 90.0f);
                            }
                        }
                    }
                }


                //---------------------------------
                // SET MOVEMENT SPEEDS
                //---------------------------------
                if (isUnderWater)
                {
                    moveSideways = 0.0f;
                }

                if (moveForward == 0.0f && moveSideways == 0.0f)
                {
                    isWalking   = false;
                    isRunning   = false;
                    isSprinting = false;
                }

                float spdLerp = 1.7f;
                if (isRunning)
                {
                    spdLerp = 2.5f;
                }
                if (isSprinting)
                {
                    spdLerp = 3.5f;
                }

                moveSpeed = walkSpeed;
                if (isInWaterDeep || isUnderWater)
                {
                    isRunning = false;
                }
                if (isRunning)
                {
                    moveSpeed = runSpeed;
                }
                if (isSprinting)
                {
                    moveSpeed = sprintSpeed;
                }

                if (moveForward != 0.0f && moveSideways != 0.0f)
                {
                    moveSpeed *= 0.5f;
                }

                float wMod = 1.0f;
                if (isInWater)
                {
                    wMod = 0.8f;
                }
                if (isInWaterDeep)
                {
                    wMod = 0.6f;
                }
                if (isUnderWater)
                {
                    wMod = 0.5f;
                }
                moveSpeed *= wMod;

                //slowmovement based on slope
                if (gSlope > 0.0f)
                {
                    if (useSlope > 0.25f && useSlope < 90.0f)
                    {
                        moveSpeed *= (1.25f - (useSlope / 90.0f));
                    }
                }

                useSpeed     = Mathf.Lerp(useSpeed, (moveSpeed * moveForward), Time.deltaTime * spdLerp);
                useSideSpeed = Mathf.Lerp(useSideSpeed, (moveSpeed * moveSideways), Time.deltaTime * spdLerp);

                if (isUnderWater || isInWater)
                {
                    useVertSpeed = Mathf.Lerp(useVertSpeed, (moveSpeed * moveVert), Time.deltaTime * spdLerp);
                }
                else
                {
                    useVertSpeed = 0.0f;
                }



                //---------------------------------
                //  CHARACTER MOVEMENT
                //---------------------------------
                if (cameraTarget.GetComponent <Rigidbody>())
                {
                    //calculate forward / backward movement
                    Vector3 setNewPos;
                    setNewPos = ((cameraTarget.transform.forward * useSpeed * moveForwardTgt));
                    if (moveForward != 0.0f && moveForwardTgt != moveForward)
                    {
                        moveForwardTgt = moveForward;
                    }

                    //calculate sideways movement
                    Vector3 setNewSidePos;
                    setNewSidePos = ((cameraTarget.transform.forward * useSideSpeed * moveSidewaysTgt));
                    if (moveSideways != 0.0f && moveSidewaysTgt != moveSideways)
                    {
                        moveSidewaysTgt = moveSideways;
                    }

                    //calculate vertical while underwater
                    Vector3 setNewVertPos;
                    setNewVertPos = new Vector3(0f, useVertSpeed, 0f);

                    //set final movement
                    cameraTarget.GetComponent <Rigidbody>().MovePosition(cameraTarget.GetComponent <Rigidbody>().position + (setNewPos + setNewSidePos + setNewVertPos));
                }


                //---------------------------------
                //  CAMERA POSITIONING
                //---------------------------------

                //Calculate Follow Distance
                float followLerpSpeed = 2.0f;
                followDistance   -= (MouseScrollDistance * 8.0f);
                followDistance    = Mathf.Clamp(followDistance, minZoomAmount, maxZoomAmount);
                followTgtDistance = Mathf.Lerp(followTgtDistance, followDistance, Time.deltaTime * followLerpSpeed);

                // Calculate Rotation
                camRotation = Mathf.Lerp(oldMouseRotation, MouseRotationDistance * axisSensitivity.x, Time.deltaTime);

                targetRotation.eulerAngles = new Vector3(
                    targetRotation.eulerAngles.x,
                    (targetRotation.eulerAngles.y + camRotation),
                    targetRotation.eulerAngles.z
                    );

                cameraObject.transform.eulerAngles = new Vector3(
                    targetRotation.eulerAngles.x,
                    targetRotation.eulerAngles.y,
                    cameraObject.transform.eulerAngles.z
                    );


                camHeight = Mathf.Lerp(camHeight, camHeight + MouseVerticalDistance * axisSensitivity.y, Time.deltaTime);
                camHeight = Mathf.Clamp(camHeight, -1.0f, 12.0f);

                // SET CAMERA POSITION and ROTATIONS
                cameraObject.transform.position = cameraTarget.transform.position + (-cameraObject.transform.forward * followTgtDistance);

                cameraObject.transform.position = new Vector3(
                    cameraObject.transform.position.x,
                    (cameraObject.transform.position.y + camHeight),
                    cameraObject.transform.position.z
                    );

                cameraObject.transform.LookAt(new Vector3(targetPosition.x, targetPosition.y + followHeight, targetPosition.z));

                //CHECK CAMERA OCCLUSION and REPOSITION
                //RaycastHit[] hits;
                Vector3 testPos = cameraTarget.transform.position;
                testPos = new Vector3(testPos.x, (testPos.y + followHeight), testPos.z);
                RaycastHit hit = new RaycastHit();
                if (Physics.Linecast(testPos, cameraObject.transform.position, out hit))
                {
                    if (hit.transform.gameObject.layer != suimonoModuleObject.layerWaterNum)
                    {
                        if (hit.transform == transform || hit.transform == cameraTarget)
                        {
                            //do nothing
                        }
                        else
                        {
                            //check for triggers
                            bool trigCheck = false;
                            if (hit.transform.GetComponent <Collider>() != null)
                            {
                                if (hit.transform.GetComponent <Collider>().isTrigger)
                                {
                                    trigCheck = true;
                                }
                            }

                            if (!trigCheck)
                            {
                                //calculate ray
                                //Ray dirRay = new Ray(testPos, testPos - cameraObject.transform.position);
                                //move camera
                                cameraObject.transform.position = hit.point;
                            }
                        }
                    }
                }

                //set camera leaning
                cameraObject.transform.eulerAngles = new Vector3(
                    cameraObject.transform.rotation.eulerAngles.x,
                    cameraObject.transform.rotation.eulerAngles.y,
                    cameraLean
                    );
            }



            //---------------------------------
            //  SET CAMERA SETTINGS and FX
            //---------------------------------
            if (isControllable)
            {
                //SET CAMERA SETTINGS
                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;
            }
        }


        //-----------------------------------
        //  SEND MODES TO CHARACTER ANIMATOR
        //------------------------------------
        if (targetAnimator != null)
        {
            targetAnimator.isWalking    = isWalking;
            targetAnimator.isRunning    = isRunning;
            targetAnimator.isSprinting  = isSprinting;
            targetAnimator.moveForward  = moveForward;
            targetAnimator.moveSideways = moveSideways;

            targetAnimator.gSlope        = gSlope;
            targetAnimator.useSlope      = useSlope;
            targetAnimator.isInWater     = isInWater;
            targetAnimator.isInWaterDeep = isInWaterDeep;
            targetAnimator.isUnderWater  = isUnderWater;
            targetAnimator.isFloating    = isFloating;
            targetAnimator.isAtSurface   = isAtSurface;
            targetAnimator.isFalling     = isFalling;

            targetAnimator.isInBoat = isInBoat;
        }
    }
    void FixedUpdate()
    {
        if (isActive)
        {
            //------------------------------------
            //  GET DATA FROM MASTER CONTROLLER
            //------------------------------------
            cameraObject = MC.cameraObject;


            //---------------------------------
            //  GET KEYBOARD AND MOUSE INPUTS
            //---------------------------------

            if (isControllable)
            {
                //"WASD" MOVEMENT KEYS
                moveForward  = 0.0f;
                moveSideways = 0.0f;
                if (IC.inputKeyW)
                {
                    moveForward = 1.0f;
                }
                if (IC.inputKeyS)
                {
                    moveForward = -1.0f;
                }
                if (IC.inputKeyA)
                {
                    moveSideways = -1.0f;
                }
                if (IC.inputKeyD)
                {
                    moveSideways = 1.0f;
                }

                //MOUSE BUTTON 0
                //isMouseMove = IC.inputMouseKey0;

                //MOUSE BUTTON 1
                isExtraZoom = IC.inputMouseKey1;
                if (isExtraZoom)
                {
                    setFOV = 0.5f;
                }
                else
                {
                    setFOV = 1.0f;
                }

                //SHIFT
                isRunning = IC.inputKeySHIFTL;
                if (moveForward == -1.0f)
                {
                    isRunning = false;
                }

                //SPACE
                //orbitView = IC.inputKeySPACE;
            }


            //CHECK FOR MOUSE INPUT
            targetPosition   = cameraTarget.position;
            oldMouseRotation = MouseRotationDistance;
            //oldMouseVRotation = MouseVerticalDistance;

            //GET MOUSE MOVEMENT
            MouseRotationDistance = IC.inputMouseX;
            MouseVerticalDistance = IC.inputMouseY;
            MouseScrollDistance   = IC.inputMouseWheel;
            if (reverseXAxis)
            {
                MouseRotationDistance = -IC.inputMouseX;
            }
            if (reverseYAxis)
            {
                MouseVerticalDistance = -IC.inputMouseY;
            }



            //---------------------------------
            //  HANDLE CAMERA VIEWS
            //---------------------------------
            if (!isControllable)
            {
                //Zoom Settings used for the intro screen
                camFOV         = 63.2f;
                followLat      = Mathf.Lerp(followLat, -0.85f, Time.deltaTime * 4.0f);
                followHeight   = Mathf.Lerp(followHeight, 1.8f, Time.deltaTime * 4.0f);
                followDistance = Mathf.Lerp(followDistance, 5.0f, Time.deltaTime * 4.0f);

                axisSensitivity = new Vector2(
                    Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f),
                    Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f)
                    );

                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;
            }

            //IDLE SETTINGS lerp camera back
            camFOV          = Mathf.Lerp(camFOV, cameraFOV * setFOV, Time.deltaTime * 4.0f);
            followLat       = Mathf.Lerp(followLat, -0.4f, Time.deltaTime * 4.0f);
            followHeight    = Mathf.Lerp(followHeight, 1.4f, Time.deltaTime * 2.0f);
            axisSensitivity = new Vector2(Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f), axisSensitivity.y);
            axisSensitivity = new Vector2(axisSensitivity.x, Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f));

            //LOCK CURSOR
            Cursor.lockState = CursorLockMode.None;


            //---------------------------------
            //  SUIMONO SPECIFIC HANDLING
            //---------------------------------
            // we use this to get the current Suimono plane water level (if applicable) from the
            // main Suimono Module object, then translate this into different walk / run speeds
            // based on water depth.
            //var waterLevel : float = suimonoModuleObject.GetWaterDepth(cameraTarget);
            if (suimonoModuleObject != null)
            {
                float waterLevel = suimonoModuleObject.SuimonoGetHeight(cameraTarget.position, "object depth");

                isInWater = false;

                if (waterLevel < 0.0f)
                {
                    waterLevel = 0.0f;
                }
                if (waterLevel > 0.0f)
                {
                    isInWater     = true;
                    isInWaterDeep = false;
                    isUnderWater  = false;
                    //isFloating = false;
                    //isAtSurface = false;

                    if (waterLevel >= 0.9f && waterLevel < 1.8f)
                    {
                        isInWaterDeep = true;
                    }
                    if (waterLevel >= 1.8f)
                    {
                        isUnderWater = true;
                    }
                    //if (waterLevel >= 1.2f && waterLevel < 1.8f) isAtSurface = true;
                    //if (isInWaterDeep && waterLevel > 2.0f) isFloating = true;
                }
            }



            //---------------------------------
            // SET MOVEMENT SPEEDS
            //---------------------------------
            float spdLerp = 5.0f;
            if (isRunning && moveForward > 0.0f)
            {
                spdLerp = 2.5f;
            }

            moveSpeed = walkSpeed;
            if (isInWaterDeep || isUnderWater)
            {
                isRunning = false;
            }
            if (isRunning)
            {
                moveSpeed = runSpeed;
            }

            if (moveForward != 0.0f && moveSideways != 0.0f)
            {
                moveSpeed *= 0.75f;
            }

            if (!isInWater)
            {
                moveSpeed *= 0.0f;
            }


            useSpeed     = Mathf.Lerp(useSpeed, (moveSpeed * moveForward), Time.deltaTime * spdLerp);
            useSideSpeed = Mathf.Lerp(useSideSpeed, (moveSpeed * moveSideways), Time.deltaTime * spdLerp);



            //---------------------------------
            //  CHARACTER POSITIONING
            //---------------------------------

            if (isControllable)
            {
                //ROTATE BOAT
                if (moveForward != 0.0f)
                {
                    xMove = Mathf.Lerp(xMove, useSpeed, Time.deltaTime);
                    zMove = Mathf.Lerp(zMove, useSpeed, Time.deltaTime);
                    cameraTarget.eulerAngles = new Vector3(
                        cameraTarget.eulerAngles.x,
                        (cameraTarget.eulerAngles.y + Mathf.Lerp(0.0f, 20.0f * moveSideways * moveForward, Time.deltaTime * (Mathf.Abs(xMove * 10.0f)))),
                        cameraTarget.eulerAngles.z
                        );
                    if (isInWater)
                    {
                        cameraTarget.eulerAngles = new Vector3(
                            cameraTarget.eulerAngles.x,
                            cameraTarget.eulerAngles.y,
                            (cameraTarget.eulerAngles.z + Mathf.Lerp(0.0f, -130.0f * moveSideways * moveForward, Time.deltaTime * (Mathf.Abs(zMove * 5.0f))))
                            );
                    }
                }
                else
                {
                    xMove = Mathf.Lerp(xMove, 0.0f, Time.deltaTime);
                }


                //MOVE BOAT
                if (cameraTarget.GetComponent <Rigidbody>())
                {
                    //calculate forward / backward movement
                    Vector3 setNewPos;
                    setNewPos = ((cameraTarget.transform.forward * (xMove)));

                    //calculate vertical while underwater
                    Vector3 setNewVertPos = new Vector3(0f, 0f, 0f);

                    //set final movement
                    cameraTarget.GetComponent <Rigidbody>().MovePosition(cameraTarget.GetComponent <Rigidbody>().position + (setNewPos + setNewVertPos));
                }



                //---------------------------------
                //  CAMERA POSITIONING
                //---------------------------------

                //Calculate Follow Distance
                float followLerpSpeed = 2.0f;
                followDistance   -= (MouseScrollDistance * 8.0f);
                followDistance    = Mathf.Clamp(followDistance, minZoomAmount, maxZoomAmount);
                followTgtDistance = Mathf.Lerp(followTgtDistance, followDistance, Time.deltaTime * followLerpSpeed);

                // Calculate Rotation
                camRotation = Mathf.Lerp(oldMouseRotation, MouseRotationDistance * axisSensitivity.x, Time.deltaTime);
                targetRotation.eulerAngles         = new Vector3(targetRotation.eulerAngles.x, (targetRotation.eulerAngles.y + camRotation), targetRotation.eulerAngles.z);
                cameraObject.transform.eulerAngles = new Vector3(targetRotation.eulerAngles.x, cameraObject.transform.eulerAngles.y, cameraObject.transform.eulerAngles.z);
                cameraObject.transform.eulerAngles = new Vector3(cameraObject.transform.eulerAngles.x, targetRotation.eulerAngles.y, cameraObject.transform.eulerAngles.z);

                camHeight = Mathf.Lerp(camHeight, camHeight + MouseVerticalDistance * axisSensitivity.y, Time.deltaTime);
                camHeight = Mathf.Clamp(camHeight, -1.0f, 12.0f);

                // SET CAMERA POSITION and ROTATIONS
                cameraObject.transform.position = cameraTarget.transform.position + (-cameraObject.transform.forward * followTgtDistance);
                cameraObject.transform.position = new Vector3(cameraObject.transform.position.x, (cameraObject.transform.position.y + camHeight), cameraObject.transform.position.z);
                cameraObject.transform.LookAt(new Vector3(targetPosition.x, targetPosition.y + followHeight, targetPosition.z));

                //CHECK CAMERA OCCLUSION and REPOSITION
                //RaycastHit[] hits;
                Vector3 testPos = cameraTarget.transform.position;
                testPos = new Vector3(testPos.x, (testPos.y + followHeight), testPos.z);
                RaycastHit hit = new RaycastHit();
                if (Physics.Linecast(testPos, cameraObject.transform.position, out hit))
                {
                    if (hit.transform.gameObject.layer != 4)
                    {
                        if (hit.transform == transform || hit.transform == cameraTarget)
                        {
                            //do nothing
                        }
                        else
                        {
                            //check for triggers
                            bool trigCheck = false;
                            if (hit.transform.GetComponent <Collider>() != null)
                            {
                                if (hit.transform.GetComponent <Collider>().isTrigger)
                                {
                                    trigCheck = true;
                                }
                            }

                            if (!trigCheck)
                            {
                                //calculate ray
                                //Ray dirRay = new Ray(testPos, testPos - cameraObject.transform.position);
                                //move camera
                                cameraObject.transform.position = hit.point;
                            }
                        }
                    }
                }

                //set camera offset
                cameraObject.transform.position = new Vector3((cameraObject.transform.position.x + cameraOffset.x), cameraObject.transform.position.y, cameraObject.transform.position.z);
                cameraObject.transform.position = new Vector3(cameraObject.transform.position.x, (cameraObject.transform.position.y + cameraOffset.y), cameraObject.transform.position.z);

                //set camera leaning
                cameraObject.transform.eulerAngles = new Vector3(
                    cameraObject.transform.rotation.eulerAngles.x,
                    cameraObject.transform.rotation.eulerAngles.y,
                    cameraLean);
            }



            //---------------------------------
            //  SET CAMERA SETTINGS and FX
            //---------------------------------
            if (isControllable)
            {
                //SET CAMERA SETTINGS
                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;
            }



            //------------------------------------
            //  SEND MODES TO CHARACTER ANIMATOR
            //------------------------------------
            if (targetAnimator != null)
            {
                //send normal animations
                if (moveForward > 0.0f)
                {
                    targetAnimator.behaviorIsRevving     = true;
                    targetAnimator.behaviorIsRevvingHigh = isRunning;
                    targetAnimator.behaviorIsRevvingBack = false;
                }
                else if (moveForward < 0.0f)
                {
                    targetAnimator.behaviorIsRevving     = false;
                    targetAnimator.behaviorIsRevvingHigh = false;
                    targetAnimator.behaviorIsRevvingBack = true;
                }
                else if (moveForward == 0.0f)
                {
                    targetAnimator.behaviorIsRevving     = false;
                    targetAnimator.behaviorIsRevvingHigh = false;
                    targetAnimator.behaviorIsRevvingBack = false;
                }
                targetAnimator.engineRotation = moveSideways;
            }
        }

        if (targetAnimator != null)
        {
            targetAnimator.behaviorIsOn = isActive;
        }
    }