예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        bool canPull = _tempInstanceOfHook != null && _tempInstanceOfHook.GetComponent <GrapplingHook3D>().attached;

        if (canPull)
        {
            _deltaFromHook = _tempInstanceOfHook.transform.position - transform.position;   //distance from the hook to this game object - vector is facing towards the hook
            //"Collects" the hook if the player is too close to it.
            if (_deltaFromHook.magnitude < _distanceFromDetach && _shootHook.GetAxis() == 0)
            {
                _cannotHook = false;    //re-enables mid-air hooking because the hook is reset (destroyed)
                DestroyHook();
            }
            //----------------------------------------------------
        }
        if (_shootHook.GetAxisBool() && !_cannotHook && !WallBlockingPath())
        {
            if (canPull)
            {
                RaycastHit hit           = _tempInstanceOfHook.GetComponent <GrapplingHook3D>().objectHit;
                Vector3    deltaFromProp = _player.transform.position - hit.transform.position; //distance from the prop hit to the player - vector is facing towards the player
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(deltaFromProp.normalized * _pullSpeed, ForceMode.Force);  //pulls the object hit towards the player
                }
                _player.GetComponent <Rigidbody>().AddForce(_deltaFromHook.normalized * _pullSpeed); //pulls the player towards the object hit
                return;
            }
            _tempInstanceOfHook = Instantiate(hookPrefab, transform.position, _cam.transform.rotation * Quaternion.AngleAxis(-90, Vector3.up) /* * Quaternion.AngleAxis(10, Vector3.forward)*/); //makes an instance of a hook
            Physics.IgnoreCollision(_tempInstanceOfHook.GetComponent <Collider>(), _player.GetComponent <Collider>(), true);                                                                     //ignores collision with player
            _cannotHook = true;                                                                                                                                                                  //disables mid-air hooking
        }

        if (_releaseHook.GetAxis() > 0 && (canPull || (_tempInstanceOfHook != null && _tempInstanceOfHook.GetComponent <GrapplingHook3D>().canReturn)))
        {
            _cannotHook = false;    //re-enables mid-air hooking because the hook is reset (destroyed)
            DestroyHook();
        }
    }
예제 #2
0
    private void UpdateCameraRotation()
    {
        _rotationY += _verticalInput.GetInvertedAxis(SettingsComponent.gl_InvertVerticalOrientation) * ySensitivity * Time.deltaTime;
        if (_rotateZInput.GetAxisBool())
        {
            _rotationZ += _horizontalInput.GetAxis() * zSensitivity * Time.deltaTime;
        }
        else
        {
            if (SettingsComponent.gl_UseInvertedControlsUpsideDown)
            {
                if (_rotationY >= SettingsComponent.gl_InvertAngle || _rotationY <= -SettingsComponent.gl_InvertAngle)
                {
                    _rotationX += -_horizontalInput.GetAxis() * xSensitivity * Time.deltaTime;
                }
                else
                {
                    _rotationX += _horizontalInput.GetAxis() * xSensitivity * Time.deltaTime;
                }
            }
            else
            {
                _rotationX += _horizontalInput.GetAxis() * xSensitivity * Time.deltaTime;
            }
        }

        if (xClampAngle != 0)
        {
            _rotationX = ClampAngle(_rotationX, -xClampAngle, xClampAngle);
        }
        else
        {
            ResetAngle(ref _rotationX);
        }
        if (yClampAngle != 0)
        {
            _rotationY = ClampAngle(_rotationY, -yClampAngle, yClampAngle);
        }
        else
        {
            ResetAngle(ref _rotationY);
        }
        if (zClampAngle != 0)
        {
            _rotationZ = ClampAngle(_rotationZ, -zClampAngle, zClampAngle);
        }
        else
        {
            ResetAngle(ref _rotationZ);
        }
        //Debug.Log("Rotation X " + _rotationX);
        //Debug.Log("Rotation Y " + _rotationY);
        //Debug.Log("Rotation Z " + _rotationZ);

        //Vector3 localNormalUp = (up.transform.position - player.transform.position).normalized;
        //Vector3 localNormalLeft = (left.transform.position - player.transform.position).normalized;
        //Vector3 localNormalForward = (forward.transform.position - player.transform.position).normalized;

        Quaternion xQuaternion = Quaternion.AngleAxis(_rotationX, Vector3.up);
        Quaternion yQuaternion = Quaternion.AngleAxis(_rotationY, Vector3.left);

        //Quaternion zQuaternion = Quaternion.AngleAxis(_rotationZ, Vector3.forward);

        _player.transform.rotation = _playerOriginalRotation * xQuaternion /* * zQuaternion*/; //rotates the player horizontally
        transform.localRotation    = _originalRotation * yQuaternion;                          //rotates the camera vertically
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        //Interact
        if (m_interactControl.GetAxisOnce())
        {
            _interact.Activate(_interactDistance);
        }

        if (_buttonHold && m_interactControl.GetAxisBool())
        {
            _hold.HoldItem(_interactDistance, _holdDistance, _holdRadiusCheck, _physicsBasedHolding);
        }
        if (!_buttonHold && m_interactControl.GetAxisOnce())
        {
            _hold.ClickHoldItem(_interactDistance, _holdDistance, _physicsBasedHolding);
        }

        if (m_modifierLeftButton.GetAxisBool() && _hold.heldObject != null)
        {
            //Rotate Object
        }

        //Jump
        float jumpInput;
        float verticalJumpInput;

        //if ( _useInvertedControlsUpsideDown )
        //{
        if (Camera.main.GetComponent <CameraControl>().rotationY >= SettingsComponent.gl_InvertAngle || Camera.main.GetComponent <CameraControl>().rotationY <= -SettingsComponent.gl_InvertAngle)
        {
            jumpInput         = -m_jumpControl.GetAxis();
            verticalJumpInput = -m_playerVerticalInput.GetAxis();
        }
        else
        {
            jumpInput         = m_jumpControl.GetAxis();
            verticalJumpInput = m_playerVerticalInput.GetAxis();
        }
        //}
        //else
        //{
        //    jumpInput = m_jumpControl.GetAxis();
        //    verticalJumpInput = m_playerVerticalInput.GetAxis();
        //}

        float jumpBoost = _jump.HoldBoostF(jumpInput, gameObject, _jumpRadius, _jumpBoostMax);

        if (jumpBoost != 0 && jumpInput == 0)
        {
            _jump.BoostJump(gameObject, m_playerHorizontalInput.GetAxis(), verticalJumpInput);
        }

        //Wall Movement
        _wallMovement.WallMove(verticalJumpInput, m_playerHorizontalInput.GetAxis(), gameObject, _jumpRadius, _wallGlideSpeed);

        //ObjectiveHint
        if (m_objectiveHintControl.GetAxisBool())
        {
            _ui_objectiveText.PopUp();
            _ui_objectiveIcon.PopUp();
        }
    }