//Performs Shield ability //NOTE: Also need to pass in bool if that's how I'm gonna handle animationss public void Shield(ref PlayerState playerState) { switch (shieldState) { case ShieldState.Setup: //Activate shield collider here playerFaceDirection = orientationSystem.DetermineDirectionFromVector(moveInfo.GetLastMove()); ActivateCorrespondingCollider(playerFaceDirection); //Debug.Log (playerFaceDirection); //Play animation animator.Play("Shield State"); shieldState = ShieldState.Shielding; break; case ShieldState.Shielding: //NOTE: if strafing, play strafe animation Strafe(); //If player is shielding, stay in this state; else, exit state if (isShielding()) { //Stay in this state } else { DeactivateCorrespondingCollider(playerFaceDirection); shieldState = ShieldState.Setup; playerState = PlayerState.Default; return; } //Check for Grab, Dodge, or (maybe) Jump inputs //Grab if (Input.GetButtonDown("AttackPS4")) { //shieldColliderUp.enabled = false; //Switch to grab state } else if (Input.GetButtonDown("SprintPS4")) { //Check if there's any movement if (playerMoving) { //Switch to DodgeRoll state DeactivateCorrespondingCollider(playerFaceDirection); shieldState = ShieldState.Setup; playerState = PlayerState.DodgeRolling; } } break; } } //Shield
//===============HELPER FUNCTIONS THAT DO THE MOVING======================= //NOTE: "acceleration" is useless now that I'm using raw input //Handles player movement from user input private void MovePlayer() { //Get player input float moveHorizontal = (Input.GetAxisRaw("Horizontal")) * acceleration; float moveVertical = (Input.GetAxisRaw("Vertical")) * acceleration; Sprint(ref moveHorizontal, ref moveVertical); //Move the Player according to raw input //if (moveHorizontal > 0.5f || moveHorizontal < -0.5f || moveVertical > 0.5f || moveVertical < -0.5f) { if (moveHorizontal > 0f || moveHorizontal < -0f || moveVertical > 0f || moveVertical < -0f) { //To make sure diagonal movement isn't faster Vector2 moveDir = new Vector2(moveHorizontal, moveVertical); if (moveDir.magnitude > 1f) { moveDir.Normalize(); moveHorizontal = moveDir.x; moveVertical = moveDir.y; } //Move player Mathf.Clamp(moveVertical, -1f, 1f); Mathf.Clamp(moveHorizontal, -1f, 1f); playerBody.velocity = new Vector2(moveHorizontal * moveSpeed, moveVertical * moveSpeed); playerMoving = true; //Update variables that contain info about movement lastMove = new Vector2(moveHorizontal, moveVertical); playerOrientation = orientationSystem.DetermineDirectionFromVector(lastMove); } else { playerMoving = false; } //Stop the player from moving when velocity is 0 if ((moveHorizontal < 0.1f && moveHorizontal > -0.1f) || (moveVertical < 0.1F && moveVertical > -0.1f)) { playerBody.velocity = new Vector2(moveHorizontal * moveSpeed, moveVertical * moveSpeed); } }
/// <summary> /// Modifies the hold position to the direction the player is /// facing when performing a grab. /// </summary> void ModifyHoldPosition() { switch (oSystem.DetermineDirectionFromVector(moveInfo.GetLastMove())) { case EightDirections.North: holdPosition.localPosition = new Vector2(0, .15f); break; case EightDirections.NorthEast: holdPosition.localPosition = new Vector2(.106f, .106f); break; case EightDirections.East: holdPosition.localPosition = new Vector2(.15f, 0); break; case EightDirections.SouthEast: holdPosition.localPosition = new Vector2(.106f, -.106f); break; case EightDirections.South: holdPosition.localPosition = new Vector2(0, -.15f); break; case EightDirections.SouthWest: holdPosition.localPosition = new Vector2(-.106f, -.106f); break; case EightDirections.West: holdPosition.localPosition = new Vector2(-.15f, 0); break; case EightDirections.NorthWest: holdPosition.localPosition = new Vector2(-.106f, .106f); break; } }