コード例 #1
0
ファイル: PlayerInput.cs プロジェクト: aksharamurda/ZmbV2
        protected virtual void UpdateTarget()
        {
            if (_controller == null)
            {
                return;
            }



            var camera = Camera;

            if (camera == null)
            {
                return;
            }

            var lookPosition = camera.transform.position + camera.transform.forward * 1000;

            _controller.LookTargetInput             = lookPosition;
            _controller.GrenadeHorizontalAngleInput = Util.AngleOfVector(camera.transform.forward);
            _controller.GrenadeVerticalAngleInput   = Mathf.Asin(camera.transform.forward.y) * 180f / Mathf.PI;

            var closestHit = Util.GetClosestHit(camera.transform.position, lookPosition, Vector3.Distance(camera.transform.position, _motor.Top), gameObject);

            if (_motor.TurnSettings.IsAimingPrecisely)
            {
                closestHit += transform.forward;
            }

            _controller.FireTargetInput = closestHit;
        }
コード例 #2
0
ファイル: PlayerInput.cs プロジェクト: aksharamurda/ZmbV2
        protected virtual void UpdateMovement()
        {
            var movement = new PlayerMovement();

            var direction = Input.GetAxis("Horizontal") * Vector3.right +
                            Input.GetAxis("Vertical") * Vector3.forward;

            var lookAngle = Util.AngleOfVector(_controller.LookTargetInput - _motor.transform.position);

            if (direction.magnitude > float.Epsilon)
            {
                movement.Direction = Quaternion.Euler(0, lookAngle, 0) * direction.normalized;
            }

            if (_controller.ZoomInput)
            {
                movement.Magnitude = 0.5f;
            }
            else
            {
                if (_motor.Gun != null)
                {
                    if (Input.GetButton("Run") && !_motor.IsCrouching)
                    {
                        movement.Magnitude = 2.0f;
                    }
                    else
                    {
                        movement.Magnitude = 1.0f;
                    }
                }
                else
                {
                    if (Input.GetButton("Run"))
                    {
                        movement.Magnitude = 1.0f;
                    }
                    else
                    {
                        movement.Magnitude = 0.5f;
                    }
                }
            }

            _controller.MovementInput = movement;
        }
コード例 #3
0
        private void updateMovement()
        {
            var movement = MovementInput;

            if (_motor.IsInCover || _motor.IsLookingBackFromCover)
            {
                if (!_wasInCover)
                {
                    _wasInCover = true;
                    _coverTimer = 0;
                }
                else
                {
                    _coverTimer += Time.deltaTime;
                }

                if (_coverTimer < 0.5f && (movement.Direction.magnitude < 0.1f || Vector3.Dot(movement.Direction, _motor.Cover.Forward) > -0.1f))
                {
                    movement.Direction = (movement.Direction + _motor.Cover.Forward).normalized;
                }
            }
            else
            {
                _wasInCover = false;
            }

            var wasSprinting = _isSprinting;

            _isSprinting = false;

            if (movement.IsMoving)
            {
                _isActivelyFacing = true;

                // Smooth sprinting turns
                if (movement.Magnitude > 1.1f && !_motor.IsInCover)
                {
                    var lookAngle = Util.AngleOfVector(LookTargetInput - _motor.transform.position);

                    // Don't allow sprinting backwards
                    if (Mathf.Abs(Mathf.DeltaAngle(lookAngle, Util.AngleOfVector(movement.Direction))) < 100)
                    {
                        var wantedAngle = Util.AngleOfVector(movement.Direction);
                        var bodyAngle   = _motor.transform.eulerAngles.y;
                        var delta       = Mathf.DeltaAngle(bodyAngle, wantedAngle);

                        const float MaxSprintTurn = 60;

                        if (delta > MaxSprintTurn)
                        {
                            movement.Direction = Quaternion.AngleAxis(bodyAngle + MaxSprintTurn, Vector3.up) * Vector3.forward;
                        }
                        else if (delta < -MaxSprintTurn)
                        {
                            movement.Direction = Quaternion.AngleAxis(bodyAngle - MaxSprintTurn, Vector3.up) * Vector3.forward;
                        }

                        _motor.SetBodyLookTarget(_motor.transform.position + movement.Direction * 100);
                        _motor.InputPossibleImmediateTurn(false);

                        _isSprinting = true;
                    }
                    else
                    {
                        movement.Magnitude = 1.0f;
                    }
                }

                if (!_isSprinting && wasSprinting)
                {
                    _postSprintNoAutoAim = 0.0f;
                }
            }
            else if (wasSprinting)
            {
                _postSprintNoAutoAim = 0.3f;
            }

            _motor.InputMovement(movement);
        }