Example #1
0
        /// <summary> Calculate the player's non-normalized desired velocity. </summary>
        private Vector3 CheckMovementInput()
        {
            var desiredVelocity = new DesiredVelocity();

            if (MoveForward.IsDown)
            {
                desiredVelocity.Forward();
            }

            if (MoveBackward.IsDown)
            {
                desiredVelocity.Backward();
            }

            if (MoveLeft.IsDown)
            {
                desiredVelocity.Left();
            }

            if (MoveRight.IsDown)
            {
                desiredVelocity.Right();
            }

            return(desiredVelocity.Velocity);
        }
Example #2
0
        public void Start()
        {
            _transform       = Owner.GetComponent <Transform>();
            _inventory       = Owner.GetComponent <InventoryBehavior>();
            _cameraTransform = Camera.main.GetComponent <Transform>();
            _playerCursor    = GetComponentInChildren <CursorBehavior>().PlayerCursor;
            _desiredVelocity = new DesiredVelocity();

            SetMouseLock(true);

            _gameControls = new InputActionCollection()
            {
                { KeyboardEventType.ToggleDown, KeyCode.F5, ReloadLevel },
                { KeyboardEventType.ToggleDown, KeyCode.F1, PauseGame },
                { KeyboardEventType.ToggleDown, KeyCode.F2, UnpauseGame },
            };

            _inputAction = new InputActionCollection()
            {
                { KeyboardEventType.Down, KeyCode.W, () => _desiredVelocity.Forward() },
                { KeyboardEventType.Down, KeyCode.S, () => _desiredVelocity.Backward() },
                { KeyboardEventType.Down, KeyCode.A, () => _desiredVelocity.Left() },
                { KeyboardEventType.Down, KeyCode.D, () => _desiredVelocity.Right() },
                { KeyboardEventType.Down, KeyCode.Alpha1, () => _inventory.TrySwitchTo(0) },
                { KeyboardEventType.Down, KeyCode.Alpha2, () => _inventory.TrySwitchTo(1) },
                { KeyboardEventType.Down, KeyCode.Alpha3, () => _inventory.TrySwitchTo(2) },
                { KeyboardEventType.Down, KeyCode.Alpha4, () => _inventory.TrySwitchTo(3) },
                { KeyboardEventType.Down, KeyCode.Alpha5, () => _inventory.TrySwitchTo(4) },
                { KeyboardEventType.Down, KeyCode.Alpha6, () => _inventory.TrySwitchTo(5) },
                { KeyboardEventType.Down, KeyCode.Alpha7, () => _inventory.TrySwitchTo(6) },
                { KeyboardEventType.Down, KeyCode.Alpha8, () => _inventory.TrySwitchTo(7) },
                { KeyboardEventType.Down, KeyCode.Alpha9, () => _inventory.TrySwitchTo(8) },
                { KeyboardEventType.Down, KeyCode.Alpha0, () => _inventory.TrySwitchTo(9) },
                { KeyboardEventType.Down, KeyCode.R, () => _inventory.TryReload() },
                { MouseEventType.ButtonDown, MouseButton.LeftButton, () => _inventory.TryTrigger1() },
                { MouseEventType.ButtonDown, MouseButton.RightButton, () => _inventory.TryTrigger2() },
            };
        }