private void FixedUpdate()
        {
            float speed;

            GetInput(out speed);
            // always move along the camera forward as it is the direction that it being aimed at
            Vector3 desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x;

            // get a normal for the surface that is being touched to move along it
            RaycastHit hitInfo;

            Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
                               m_CharacterController.height / 2f);
            desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

            m_MoveDir.x = desiredMove.x * speed;
            m_MoveDir.z = desiredMove.z * speed;


            if (m_CharacterController.isGrounded)
            {
                m_MoveDir.y = -m_StickToGroundForce;

                if (m_Jump)
                {
                    m_MoveDir.y = m_JumpSpeed;
                    PlayJumpSound();
                    m_Jump    = false;
                    m_Jumping = true;
                }
            }
            else
            {
                m_MoveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime;
            }
            m_CollisionFlags = m_CharacterController.Move(m_MoveDir * Time.fixedDeltaTime);

            ProgressStepCycle(speed);
            UpdateCameraPosition(speed);

            inputHandle.InputHandle();
        }
Example #2
0
        protected virtual void Update()
        {
            if (useProfileData)
            {
                if (InitialPose == null)
                {
                    // Save the initial pose so it can be recovered if useProfileData
                    // is turned off later.
                    InitialPose = new OVRPose()
                    {
                        position    = CameraRig.transform.localPosition,
                        orientation = CameraRig.transform.localRotation
                    };
                }

                var p = CameraRig.transform.localPosition;
                p.y = OVRManager.profile.eyeHeight - 0.5f * Controller.height
                      + Controller.center.y;
                CameraRig.transform.localPosition = p;
            }
            else if (InitialPose != null)
            {
                // Return to the initial pose if useProfileData was turned off at runtime
                CameraRig.transform.localPosition = InitialPose.Value.position;
                CameraRig.transform.localRotation = InitialPose.Value.orientation;
                InitialPose = null;
            }

            //print(CameraRig.centerEyeAnchor.localEulerAngles.x);
            //if (CameraRig.centerEyeAnchor.localEulerAngles.x > 30 && CameraRig.centerEyeAnchor.localEulerAngles.x < 80)
            //{
            //    GameObject.Find("pallette").GetComponentInChildren<Renderer>().enabled = true;
            //   foreach (Renderer colorBalls in GameObject.Find("pallette").GetComponentsInChildren<Renderer>())
            //    {
            //        colorBalls.enabled = true;
            //   }
            //GameObject.Find("crosshair").transform.localScale = new Vector3(1, 1, 1);

            RaycastHit pallettehit;

            if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out pallettehit))
            {
                if (pallettehit.transform.tag == "pallette" || pallettehit.transform.tag == "ColorSelect" || pallettehit.transform.tag == "ColorMix")
                {
                    pallettehit.transform.GetComponentInChildren <Renderer>().enabled = true;
                    foreach (Renderer colorBalls in pallettehit.transform.GetComponentsInChildren <Renderer>())
                    {
                        colorBalls.enabled = true;
                    }
                    GameObject.Find("crosshair").transform.localScale = new Vector3(1, 1, 1);
                }
                else
                {
                    GameObject.Find("pallette").transform.GetComponentInChildren <Renderer>().enabled = false;
                    foreach (Renderer colorBalls in GameObject.Find("pallette").transform.GetComponentsInChildren <Renderer>())
                    {
                        colorBalls.enabled = false;
                    }
                    GameObject.Find("crosshair").transform.localScale = new Vector3(0, 0, 0);
                }
            }

            // } else {
            //GameObject.Find("pallette").GetComponentInChildren<Renderer>().enabled = false;
            //foreach (Renderer colorBalls in GameObject.Find("pallette").GetComponentsInChildren<Renderer>())
            //{
            //    colorBalls.enabled = false;
            //}
            //GameObject.Find("crosshair").transform.localScale = new Vector3(0,0,0);
            // }
            UpdateMovement();

            Vector3 moveDirection = Vector3.zero;

            inputHandle.InputHandle();

            float motorDamp = (1.0f + (Damping * SimulationRate * Time.deltaTime));

            MoveThrottle.x /= motorDamp;
            MoveThrottle.y  = (MoveThrottle.y > 0.0f) ? (MoveThrottle.y / motorDamp) : MoveThrottle.y;
            MoveThrottle.z /= motorDamp;

            moveDirection += MoveThrottle * SimulationRate * Time.deltaTime;

            // Gravity

            /*if (Controller.isGrounded && FallSpeed <= 0)
             *  FallSpeed = ((Physics.gravity.y * (GravityModifier * 0.002f)));
             * else
             *  FallSpeed += ((Physics.gravity.y * (GravityModifier * 0.002f)) * SimulationRate * Time.deltaTime);
             *
             * moveDirection.y += FallSpeed * SimulationRate * Time.deltaTime;*/

            // Offset correction for uneven ground
            float bumpUpOffset = 0.0f;

            if (Controller.isGrounded && MoveThrottle.y <= transform.lossyScale.y * 0.001f)
            {
                bumpUpOffset   = Mathf.Max(Controller.stepOffset, new Vector3(moveDirection.x, 0, moveDirection.z).magnitude);
                moveDirection -= bumpUpOffset * Vector3.up;
            }

            Vector3 predictedXZ = Vector3.Scale((Controller.transform.localPosition + moveDirection), new Vector3(1, 0, 1));

            // Move contoller
            //Controller.Move(moveDirection);

            Vector3 actualXZ = Vector3.Scale(Controller.transform.localPosition, new Vector3(1, 0, 1));

            if (predictedXZ != actualXZ)
            {
                MoveThrottle += (actualXZ - predictedXZ) / (SimulationRate * Time.deltaTime);
            }
        }