void HandlePlayerInput() { PlayerCharacterInputstruct playercharacterinputs = new PlayerCharacterInputstruct(); playercharacterinputs.MoveAxisForward = Input.GetAxisRaw("Vertical"); playercharacterinputs.MoveAxisRight = Input.GetAxisRaw("Horizontal"); playercharacterinputs.CameraRotation = orbitCamera.transform.rotation; playercharacterinputs.JumpDown = Input.GetButtonDown("Jump"); playercharacterinputs.JumpUp = Input.GetButtonUp("Jump"); playercharacterinputs.DashingDown = Input.GetKeyDown(KeyCode.Q); character.SetInputs(ref playercharacterinputs); }
/// This is called every frame by MyPlayer in order to tell the character what its inputs are public void SetInputs(ref PlayerCharacterInputstruct inputs) { if (inputs.DashingDown) { TransitionToState(CharacterStates.Dashing); } // Clamp input Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f); // Calculate camera direction and rotation on the character plane Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized; if (cameraPlanarDirection.sqrMagnitude == 0f) { cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized; } Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp); switch (CurrentCharacterState) { case CharacterStates.Default: { // Move and look inputs _moveInputVector = cameraPlanarRotation * moveInputVector; _lookInputVector = cameraPlanarDirection; //jumping input if (inputs.JumpDown) { _timeSinceJumpRequested = 0; _jumpRequested = true; } else if (inputs.JumpUp) { _jumpReleased = true; } break; } } }