LookRotation() public method

public LookRotation ( Transform character, Transform camera ) : void
character UnityEngine.Transform
camera UnityEngine.Transform
return void
コード例 #1
0
ファイル: WallRunController.cs プロジェクト: ArcAids/Packages
    // Update is called once per frame
    void Update()
    {
        directionInput    = camTransform.right * Input.GetAxis("Horizontal") + camTransform.forward * Input.GetAxis("Vertical");
        directionInput    = Vector3.ProjectOnPlane(directionInput, Vector3.up).normalized;
        directionInput.x *= speed * Time.deltaTime;
        directionInput.z *= speed * Time.deltaTime;

        verticalVelocity -= gravityMultiplier * Time.deltaTime;
        if (Input.GetKey(KeyCode.Space) && canJump)
        {
            verticalVelocity += jumpForce;
        }
        directionInput.y = verticalVelocity * Time.deltaTime;

        controller.Move(directionInput);
        mouseLook.LookRotation(transform, camTransform);

        CollisionFlags flags = controller.collisionFlags;

        if (flags == CollisionFlags.Below)
        {
            canJump           = true;
            verticalVelocity  = gravityMultiplier * Time.deltaTime;
            gravityMultiplier = gravity;
        }
        else if (flags == CollisionFlags.Sides)
        {
            gravityMultiplier = lowGravity;
        }
        else
        {
            canJump           = false;
            gravityMultiplier = gravity;
        }
    }
コード例 #2
0
    protected void Update()
    {
        // If we are falling increment timer
        if (_characterController.isGrounded)
        {
            _fallingTimer = 0.0f;
        }
        else
        {
            _fallingTimer += Time.deltaTime;
        }

        // Allow Mouse Look a chance to process mouse and rotate camera
        if (Time.timeScale > Mathf.Epsilon)
        {
            _mouseLook.LookRotation(transform, _camera.transform);
        }

        // Process the Jump Button
        // the jump state needs to read here to make sure it is not missed
        if (!_jumpButtonPressed)
        {
            _jumpButtonPressed = Input.GetButtonDown("Jump");
        }

        // Calculate Character Status
        if (!_previouslyGrounded && _characterController.isGrounded)
        {
            if (_fallingTimer > 0.5f)
            {
                // TODO: Play Landing Sound
            }

            _moveDirection.y = 0f;
            _isJumping       = false;
            _movementStatus  = PlayerMoveStatus.Landing;
        }
        else
        if (!_characterController.isGrounded)
        {
            _movementStatus = PlayerMoveStatus.NotGrounded;
        }
        else
        if (_characterController.velocity.sqrMagnitude < 0.01f)
        {
            _movementStatus = PlayerMoveStatus.NotMoving;
        }
        else
        if (_isWalking)
        {
            _movementStatus = PlayerMoveStatus.Walking;
        }
        else
        {
            _movementStatus = PlayerMoveStatus.Running;
        }

        _previouslyGrounded = _characterController.isGrounded;
    }
コード例 #3
0
    protected void Update()
    {
        if (_characterController.isGrounded)
        {
            _fallingTimer = 0.0f;
        }
        else
        {
            _fallingTimer += Time.deltaTime;
        }

        //helps mouselook have time to process mouse and rotate camera
        if (Time.timeScale > Mathf.Epsilon)
        {
            _mouseLook.LookRotation(transform, _camera.transform);
        }

        if (!_jumpButtonPressed)
        {
            _jumpButtonPressed = Input.GetButtonDown("Jump");
        }

        //calculating character status
        if (!_previouslyGrounded && _characterController.isGrounded)
        {
            if (_fallingTimer > 0.5f)
            {
                //sound
            }

            _moveDirection.y = 0f;
            _isJumping       = false;
            _movementStatus  = PlayerMoveStatus.Landing;
        }
        else
        if (!_characterController.isGrounded)
        {
            _movementStatus = PlayerMoveStatus.NotGrounded;
        }
        else
        if (_characterController.velocity.sqrMagnitude < 0.01f)
        {
            _movementStatus = PlayerMoveStatus.NotMoving;
        }
        else
        if (_isWalking)
        {
            _movementStatus = PlayerMoveStatus.Walking;
        }
        else
        {
            _movementStatus = PlayerMoveStatus.Running;
        }

        _previouslyGrounded = _characterController.isGrounded;
    }
コード例 #4
0
        private void RotateView()
        {
            //avoids the mouse looking if the game is effectively paused
            if (Mathf.Abs(Time.timeScale) < float.Epsilon)
            {
                return;
            }

            // get the rotation before it's changed
            float oldYRotation = transform.eulerAngles.y;

            mouseLook.LookRotation(transform, cam.transform);

            if (m_IsGrounded || advancedSettings.airControl)
            {
                // Rotate the rigidbody velocity to match the new direction that the character is looking
                Quaternion velRotation = Quaternion.AngleAxis(transform.eulerAngles.y - oldYRotation, Vector3.up);
                m_RigidBody.velocity = velRotation * m_RigidBody.velocity;
            }
        }
コード例 #5
0
    protected void Update()
    {
        if (Time.timeScale != 0)
        {
            // If grounded keep falling timer at 0. Else we are falling so increment timer
            if (characterController.isGrounded)
            {
                fallingTimer = 0.0f;
            }
            else
            {
                fallingTimer += Time.deltaTime;
            }

            // First checks if game is paused, if it isnt, then reads horizontal and vertical mouse movement. Either rotates char controller left/right for horizontal mouse movement
            //or rotate camera up and down for vertical mouse movement.
            if (Time.timeScale > Mathf.Epsilon)
            {
                mouseLook.LookRotation(transform, _camera.transform);
            }


            //if player press F, flashlight set to active
            if (Input.GetButtonDown("Flashlight"))
            {
                if (flashLight)
                {
                    flashLight.SetActive(!flashLight.activeSelf);
                }
            }

            //Jump button pressed then jumpButtonpressed set to true
            if (!jumpButtonPressed && !isCrouching)
            {
                jumpButtonPressed = Input.GetButtonDown("Jump");
            }


            //character controller height is halved when crouch button pressed
            if (Input.GetButtonDown("Crouch"))
            {
                isCrouching = !isCrouching;
                if (isCrouching == true)
                {
                    characterController.height = controllerHeight / 2.0f;
                }
                else
                {
                    characterController.height = controllerHeight;
                }
            }

            // Calculates Character Status
            if (!previouslyGrounded && characterController.isGrounded)
            {
                moveDirection.y = 0f;
                isJumping       = false;
                movementStatus  = PlayerMoveStatus.Landing;
            }
            else if (!characterController.isGrounded)
            {
                movementStatus = PlayerMoveStatus.NotGrounded;
            }
            else if (characterController.velocity.sqrMagnitude < 0.01f)
            {
                movementStatus = PlayerMoveStatus.NotMoving;
            }
            else if (isCrouching)
            {
                movementStatus = PlayerMoveStatus.Crouching;
            }
            else if (isWalking)
            {
                movementStatus = PlayerMoveStatus.Walking;
            }

            else
            {
                movementStatus = PlayerMoveStatus.Running;
            }

            previouslyGrounded = characterController.isGrounded;
        }
    }
コード例 #6
0
    protected void Update()
    {
        // If we are falling increment timer
        if (_characterController.isGrounded)
        {
            _fallingTimer = 0.0f;
        }
        else
        {
            _fallingTimer += Time.deltaTime;
        }

        // Allow Mouse Look a chance to process mouse and rotate camera
        if (Time.timeScale > Mathf.Epsilon)
        {
            _mouseLook.LookRotation(transform, _camera.transform);
        }

        if (Input.GetButtonDown("Flashlight"))
        {
            if (_flashLight)
            {
                _flashLight.SetActive(!_flashLight.activeSelf);
            }
        }

        // Process the Jump Button
        // the jump state needs to read here to make sure it is not missed
        if (!_jumpButtonPressed && !_isCrouching)
        {
            _jumpButtonPressed = Input.GetButtonDown("Jump");
        }

        if (Input.GetButtonDown("Crouch"))
        {
            _isCrouching = !_isCrouching;
            _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight;
        }

        // Calculate Chatacter Status
        if (!_previouslyGrounded && _characterController.isGrounded)
        {
            if (_fallingTimer > 0.5f)
            {
                // TODO: Play Landing Sound
            }

            _moveDirection.y = 0f;
            _isJumping       = false;
            _movementStatus  = PlayerMoveStatus.Landing;
        }
        else
        if (!_characterController.isGrounded)
        {
            _movementStatus = PlayerMoveStatus.NotGrounded;
        }
        else
        if (_characterController.velocity.sqrMagnitude < 0.01f)
        {
            _movementStatus = PlayerMoveStatus.NotMoving;
        }
        else
        if (_isCrouching)
        {
            _movementStatus = PlayerMoveStatus.Crouching;
        }
        else
        if (_isWalking)
        {
            _movementStatus = PlayerMoveStatus.Walking;
        }
        else
        {
            _movementStatus = PlayerMoveStatus.Running;
        }

        _previouslyGrounded = _characterController.isGrounded;

        // Calculate Stamina
        if (_movementStatus == PlayerMoveStatus.Running)
        {
            _stamina = Mathf.Max(_stamina - _staminaDepletion * Time.deltaTime, 0.0f);
        }
        else
        {
            _stamina = Mathf.Min(_stamina + _staminaRecovery * Time.deltaTime, 100.0f);
        }


        _dragMultiplier = Mathf.Min(_dragMultiplier + Time.deltaTime, _dragMultiplierLimit);
    }
コード例 #7
0
 private void RotateView()
 {
     m_MouseLook.LookRotation(transform, m_Camera.transform);
     float h = CrossPlatformInputManager.GetAxis("Mouse X");
     float v = CrossPlatformInputManager.GetAxis("Mouse Y");
 }
コード例 #8
0
    protected void Update()
    {
        _fallingTimer += Time.deltaTime;

        // Allow Mouse Look a chance to process mouse and rotate camera
        if (Time.timeScale > Mathf.Epsilon)
        {
            _mouseLook.LookRotation(transform, _camera.transform);
        }

        if (Input.GetButtonDown("Flashlight"))
        {
            if (_flashLight)
            {
                _flashLight.SetActive(!_flashLight.activeSelf);
            }
        }

        if (!_jumpButtonPressed && !_isCrouching)
        {
            _jumpButtonPressed = Input.GetButtonDown("Jump");
        }

        if (Input.GetButtonDown("Crouch"))
        {
            _isCrouching = !_isCrouching;
            characterController.height = _isCrouching == true ? _controllerHeight / 2 : _controllerHeight;
        }

        if (!_previouslyGrounded && characterController.isGrounded)
        {
            if (_fallingTimer > 0.5f)
            {
                _fallingTimer = 0.0f;
            }

            _moveDirection.y = 0f;
            _isJumping       = false;
            _movementStatus  = PlayerMoveStatus.Landing;
        }
        else if (!characterController.isGrounded)
        {
            _movementStatus = PlayerMoveStatus.NotGrounded;
        }
        else if (characterController.velocity.sqrMagnitude < 0.01f)
        {
            _movementStatus = PlayerMoveStatus.NotMoving;
        }
        else if (_isCrouching)
        {
            _movementStatus = PlayerMoveStatus.Crouching;
        }
        else if (_isWalking)
        {
            _movementStatus = PlayerMoveStatus.Walking;
        }
        else
        {
            _movementStatus = PlayerMoveStatus.Running;
        }

        _previouslyGrounded = characterController.isGrounded;
    }
コード例 #9
0
 void RotateView()
 {
     //transform.rotation = myCamera.transform.rotation;
     m_MouseLook.LookRotation(transform, GameManager.Main.MainCamera.transform);
 }
コード例 #10
0
        private void RotateView()
        {
            m_MouseLook.LookRotation(transform, m_Camera.transform);

            //transform.localRotation = vrCamRotation.transform.rotation;
        }
コード例 #11
0
 private void RotateView()
 {
     m_MouseLook.LookRotation(transform, m_Camera.transform);
     cannonPivot.rotation = m_Camera.transform.rotation;
     helmetPivot.rotation = m_Camera.transform.rotation;
 }
コード例 #12
0
ファイル: FPSController.cs プロジェクト: Auggst/FPS-Demo
    protected void Update()
    {
        //下落计时器,在地面上则为0
        if (_characterController.isGrounded)
        {
            _fallingTimer = 0.0f;
        }
        else
        {
            _fallingTimer += Time.deltaTime;
        }

        if (Time.timeScale > Mathf.Epsilon)
        {
            _mouseLook.LookRotation(transform, _camera.transform);
        }
        //手电筒触发
        if (Input.GetButtonDown("Flashlight"))
        {
            if (_flashLight)
            {
                _flashLight.SetActive(!_flashLight.activeSelf);
            }
        }
        //跳跃判定,不可在跳跃过程中按跳跃键
        if (!_jumpButtonPressed)
        {
            _jumpButtonPressed = Input.GetButtonDown("Jump");
        }
        //爬行判定
        if (Input.GetButtonDown("Crouch"))
        {
            _isCrouching = !_isCrouching;
            _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight;
        }
        //落地时刻
        if (!_previouslyGrounded && _characterController.isGrounded)
        {
            if (_fallingTimer > 0.5f)
            {
                //TODO:落地音效
            }

            _moveDirection.y = 0f;
            _isJumping       = false;
            _movementStatus  = PlayerMoveStatus.Landing;
        }
        else //空中
        if (!_characterController.isGrounded)
        {
            _movementStatus = PlayerMoveStatus.NotGrounded;
        }
        else  //静止
        if (_characterController.velocity.sqrMagnitude < 0.01f)
        {
            _movementStatus = PlayerMoveStatus.NotMoving;
        }
        else  //行走
        if (_isWalking)
        {
            _movementStatus = PlayerMoveStatus.Walking;
        }
        else  //跑步
        {
            _movementStatus = PlayerMoveStatus.Runnig;
        }

        _previouslyGrounded = _characterController.isGrounded;
    }
コード例 #13
0
 // Update is called once per frame
 private void Update()
 {
     m_MouseLook.LookRotation(transform, m_Camera.transform);
 }
コード例 #14
0
 private void RotateView()
 {
     mouseLook.LookRotation(transform, currentCamera.transform);
 }
コード例 #15
0
 private void RotateView()
 {
     m_MouseLook.LookRotation(transform, m_cameraLook);
 }
コード例 #16
0
 private void RotateView()
 {
     if(!UnityEngine.XR.XRSettings.enabled)
         m_MouseLook.LookRotation (transform, m_Camera.transform);
 }
コード例 #17
0
 private void RotateView()
 {
     m_MouseLook.LookRotation(transform, m_Camera.transform);
 }
コード例 #18
0
 private void RotateView()
 {
     m_MouseLook.LookRotation(transform, m_Camera.transform);
     m_Cylinder.transform.localRotation = m_Camera.transform.localRotation;
     m_Cylinder.transform.RotateAroundLocal(Vector3.right, 3.14f / 2);
 }
コード例 #19
0
    protected void Update()
    {
        //falling increment timer
        if (_characterController.isGrounded)
        {
            _fallingTimer = 0.0f;
        }
        else
        {
            _fallingTimer += Time.deltaTime;
        }

        //allow time for mouse movement, game isnt paused
        if (Time.timeScale > Mathf.Epsilon)
        {
            _mouseLook.LookRotation(transform, _camera.transform);
        }

        //flashlight
        if (Input.GetButtonDown("Flashlight"))
        {
            if (_flashLight)
            {
                _flashLight.SetActive(!_flashLight.activeSelf);
            }
        }

        //jump
        if (!_jumpButtonPressed && !_isCrouching)
        {
            _jumpButtonPressed = Input.GetButtonDown("Jump");
        }

        //Crouching
        if (Input.GetButtonDown("Crouch"))
        {
            _isCrouching = !_isCrouching;
            _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight;
        }

        //jump status
        if (!_previouslyGrounded && _characterController.isGrounded)
        {
            if (_fallingTimer > 0.5f)
            {
                //TODO play landing sound
            }

            _moveDirection.y = 0f;
            _isJumping       = false;
            _movementStatus  = PlayerMoveStatus.LANDING;
        }
        else
        if (!_characterController.isGrounded)
        {
            _movementStatus = PlayerMoveStatus.NOTGROUNDED;
        }
        else
        if (_characterController.velocity.sqrMagnitude < 0.01f)
        {
            _movementStatus = PlayerMoveStatus.NOTMOVING;
        }
        else
        if (_isCrouching)
        {
            _movementStatus = PlayerMoveStatus.CROUCHING;
        }
        else
        if (_isWalking)
        {
            _movementStatus = PlayerMoveStatus.WALKING;
        }
        else
        {
            _movementStatus = PlayerMoveStatus.RUNNING;
        }

        _previouslyGrounded = _characterController.isGrounded;
    }
コード例 #20
0
 void ForceYRotation(float rotY)
 {
     mouseLook.LookRotation(transform, cam.transform);
 }