void TryDodge() { // Get input values float horizontal = 0.0f, vertical = 0.0f; horizontal = RBInput.GetAxisRawForPlayer(InputStrings.HORIZONTAL, PlayerIndex, playerDevice); vertical = RBInput.GetAxisRawForPlayer(InputStrings.VERTICAL, PlayerIndex, playerDevice); // If player isn't standing still and hits dodge button, let's dodge! if (RBInput.GetButtonDownForPlayer(InputStrings.DODGE, PlayerIndex, playerDevice) && (horizontal != 0 || vertical != 0)) { fighter.Dodge(new Vector3(horizontal, 0.0f, vertical)); } }
/* * Apply movement in the Player's desired directions according to the various speed * and movement variables. */ void TryMove() { // Get input values float horizontal = 0.0f, vertical = 0.0f; horizontal = RBInput.GetAxisRawForPlayer(InputStrings.HORIZONTAL, PlayerIndex); vertical = RBInput.GetAxisRawForPlayer(InputStrings.VERTICAL, PlayerIndex); // Convert to camera world space Vector3 direction = ConvertInputToCamera(horizontal, vertical); if (direction != Vector3.zero) { fighter.Run(direction); } }
void TryDodge() { // Get input values float horizontal = 0.0f, vertical = 0.0f; horizontal = RBInput.GetAxisRawForPlayer(InputStrings.HORIZONTAL, PlayerIndex); vertical = RBInput.GetAxisRawForPlayer(InputStrings.VERTICAL, PlayerIndex); // Convert to camera world space Vector3 direction = ConvertInputToCamera(horizontal, vertical); // If player isn't standing still and hits dodge button, let's dodge! if (RBInput.GetButtonDownForPlayer(InputStrings.DODGE, PlayerIndex) && direction != Vector3.zero) { fighter.Dodge(direction); } }
/* * Apply movement in the Player's desired directions according to the various speed * and movement variables. */ void Move() { // Get input values float horizontal = 0.0f, vertical = 0.0f; horizontal = RBInput.GetAxisRawForPlayer(InputStrings.HORIZONTAL, PlayerIndex, playerDevice); vertical = RBInput.GetAxisRawForPlayer(InputStrings.VERTICAL, PlayerIndex, playerDevice); // Determine move direction from target values float targetSpeed = 0.0f; Vector3 targetDirection = new Vector3(horizontal, 0.0f, vertical); if (targetDirection != Vector3.zero) { moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, Mathf.Infinity, 1000); moveDirection = moveDirection.normalized; if (RBInput.GetButtonForPlayer(InputStrings.SPRINT, PlayerIndex, playerDevice)) { targetSpeed = sprintspeed; } else { targetSpeed = movespeed; } } // Get movement vector Vector3 movement = (moveDirection * targetSpeed) + new Vector3(0.0f, verticalSpeed, 0.0f); movement *= Time.deltaTime; // Apply movement vector CharacterController biped = GetComponent <CharacterController> (); collisionFlags = biped.Move(movement); // Rotate to face the direction of movement immediately if (moveDirection != Vector3.zero) { transform.rotation = Quaternion.LookRotation(moveDirection); } }
/* * Apply movement in the Player's desired directions according to the various speed * and movement variables. */ void TryMove() { // Get input values float horizontal = 0.0f, vertical = 0.0f; horizontal = RBInput.GetAxisRawForPlayer(InputStrings.HORIZONTAL, PlayerIndex, playerDevice); vertical = RBInput.GetAxisRawForPlayer(InputStrings.VERTICAL, PlayerIndex, playerDevice); Vector3 direction = new Vector3(horizontal, 0.0f, vertical); if (direction != Vector3.zero) { if (RBInput.GetButtonForPlayer(InputStrings.SPRINT, PlayerIndex, playerDevice)) { fighter.Sprint(direction); } else { fighter.Run(direction); } } }
/* * Run through the vertical axis input to see if it has changed. If it has, * set the corresponding bools to let the GUI know later. */ void DetectVertAxis() { GameObject playerObj = FindActivePlayer(); InputDevice device = playerObj.GetComponent <PlayerController> ().playerDevice; float axis = RBInput.GetAxisRawForPlayer(InputStrings.VERTICAL, activePlayerIndex, device); bool axisChanged = (Mathf.Sign(axis) != Mathf.Sign(lastVertAxis)) || lastVertAxis == 0; if (axis > 0 && axisChanged) { upPressed = true; downPressed = false; } else if (axis < 0 && axisChanged) { upPressed = false; downPressed = true; } else { upPressed = false; downPressed = false; } lastVertAxis = axis; }