private void SetDirection(List<string> keys) { List<int> currPressedKeyIDS = new List<int>(); for (int i = 0; i < keys.Count; i++) currPressedKeyIDS.Add(playerInput.KeyIDs[keys[i]] ); string mostRecentKeyPress = GetMostRecentKeyPress(currPressedKeyIDS); //Set the player's direction based on the most recent key pressed. If playing different idle anims, play them here. if (mostRecentKeyPress == playerInput.PlayerKeybinds.Key_Up.ToString()) currentDirection = GlobalConstants.Direction_Indices.UP; if (mostRecentKeyPress == playerInput.PlayerKeybinds.Key_Down.ToString()) currentDirection = GlobalConstants.Direction_Indices.DOWN; if (mostRecentKeyPress == playerInput.PlayerKeybinds.Key_Left.ToString()) currentDirection = GlobalConstants.Direction_Indices.LEFT; if (mostRecentKeyPress == playerInput.PlayerKeybinds.Key_Right.ToString()) currentDirection = GlobalConstants.Direction_Indices.RIGHT; SetArmPosition(); playerAnimScript.PlayDirectionalAnimation("Player_Walk_" + DirectionName() ); shoulderAnimScript.PlayDirectionalAnimation("PlayerShoulder_Walk_" + DirectionName()); }
private void ProcessMovement(List<string> keys) { if (gameManager.CurrentGameState == GameManager.GameState.Running) { Vector2 moveDirection = Vector2.zero; if (currentState == PlayerState.Idle) { if (keys.Contains(playerInput.PlayerKeybinds.Key_Up.ToString()) || keys.Contains(playerInput.PlayerKeybinds.Key_Down.ToString()) || keys.Contains(playerInput.PlayerKeybinds.Key_Left.ToString()) || keys.Contains(playerInput.PlayerKeybinds.Key_Right.ToString())) { SetDirection(keys); switch (currentDirection) { case GlobalConstants.Direction_Indices.UP: moveDirection = GlobalConstants.UP_VECTOR; break; case GlobalConstants.Direction_Indices.DOWN: moveDirection = GlobalConstants.DOWN_VECTOR; break; case GlobalConstants.Direction_Indices.LEFT: moveDirection = GlobalConstants.LEFT_VECTOR; break; case GlobalConstants.Direction_Indices.RIGHT: moveDirection = GlobalConstants.RIGHT_VECTOR; break; } if (moveDirection != Vector2.zero) //If the player is heading a certain direction, apply movement. Move(moveDirection); prevDirectionPressed = currentDirection; prevPressedKeyIDs.Clear(); for (int i = 0; i < keys.Count; i++) { prevPressedKeyIDs.Add(playerInput.KeyIDs[keys[i]]); } } } } }