private void Update() { #region Check inputs // Get the vertical movement direction/input float vertical = Input.GetAxisRaw("Vertical"); // Check if Fire1 and Fire2 are pressed both if (Input.GetButton("Fire1") && Input.GetButton("Fire2")) { // Let the character move forward vertical = 1.0f; } // Check the autorun input _rpgMotor.ToggleAutorun(Input.GetButtonDown("Autorun Toggle")); // Get all actions that can cancel an active autorun bool stopAutorunAction = (Input.GetButtonDown("Fire1") && Input.GetButton("Fire2")) || (Input.GetButton("Fire1") && Input.GetButtonDown("Fire2")); stopAutorunAction = stopAutorunAction || Input.GetButtonDown("Vertical"); // Signal the usage of actions cancelling the autorunning _rpgMotor.StopAutorun(stopAutorunAction); // Get the horizontal movement direction/input float horizontal = Input.GetAxisRaw("Horizontal"); // Get the horizontal strafe direction/input float horizontalStrafe = Input.GetAxisRaw("Horizontal Strafe"); // Strafe if the right mouse button and the Horizontal input are pressed at once if (Input.GetButton("Fire2") && Input.GetAxisRaw("Horizontal") != 0) { // Let the character strafe instead rotating horizontalStrafe = horizontal; horizontal = 0f; } // Create and set the player's input direction inside the motor Vector3 playerDirectionInput = new Vector3(horizontalStrafe, 0, vertical); _rpgMotor.SetPlayerDirectionInput(playerDirectionInput); // Allow movement while airborne if the player wants to move forward/backwards or strafe _rpgMotor.MoveInMidAir(Input.GetButtonDown("Vertical") || Input.GetButtonDown("Horizontal Strafe") || (Input.GetButtonDown("Fire2") && Input.GetAxisRaw("Horizontal") != 0) || (Input.GetButton("Fire2") && Input.GetButtonDown("Horizontal"))); // Set the local Y axis rotation input to horizontal inside motor _rpgMotor.SetLocalRotationHorizontalInput(horizontal); // Enable sprinting inside the motor if the sprint modifier is pressed down _rpgMotor.Sprint(Input.GetButton("Sprint")); // Toggle walking inside the motor _rpgMotor.ToggleWalking(Input.GetButtonUp("Walk Toggle")); // Check if the jump button is pressed down if (Input.GetButtonDown("Jump")) { // Signal the motor to jump _rpgMotor.Jump(); } #endregion // Start the motor _rpgMotor.StartMotor(); }
void Update() { motor.MovementInput = Vector3.zero; bool forwardKeyDown = Input.GetKey(forwardKey); bool backwardKeyDown = Input.GetKey(backwardKey); bool leftKeyDown = Input.GetKey(leftKey); bool rightKeyDown = Input.GetKey(rightKey); bool jumpKeyPressed = Input.GetKeyDown(jumpKey); bool walkKeyDown = Input.GetKey(walkToggle); bool mouseLookDown = Input.GetMouseButton((int)mouseLookButton) && enableMouseLook; bool mouseLookPressed = Input.GetMouseButtonDown((int)mouseLookButton) && enableMouseLook; bool bothMiceDown = Input.GetMouseButton((int)mouseRunAndLookButton) && mouseLookDown && enableRunAndLook; bool autorunPressed = Input.GetMouseButtonDown((int)autorunToggleButton); IsRunning = !walkKeyDown; MouseLook = mouseLookDown; if (autorunPressed) { autorun = !autorun; } if (autorun || forwardKeyDown || bothMiceDown) { motor.MovementInput.z += 1f; } if (backwardKeyDown) { motor.MovementInput.z -= 1f; } if (mouseLookDown) { if (leftKeyDown) { motor.MovementInput.x -= 1f; } if (rightKeyDown) { motor.MovementInput.x += 1f; } } else { if (leftKeyDown) { motor.Yaw(-(Time.smoothDeltaTime * keyTurnSpeed)); } if (rightKeyDown) { motor.Yaw(Time.smoothDeltaTime * keyTurnSpeed); } } // Set movement speed if (motor.MovementInput.z < 0) { motor.MovementSpeed = walkKeyDown ? backwardWalkSpeed : backwardRunSpeed; } else { motor.MovementSpeed = walkKeyDown ? forwardWalkSpeed : forwardRunSpeed; } // Jump if (jumpKeyPressed) { motor.Jump(); } // Clear autorun if ((mouseLookDown && (leftKeyDown || rightKeyDown)) || forwardKeyDown || backwardKeyDown || bothMiceDown) { autorun = false; } // If we're moving, rotate camera behind us if (motor.MovementInput != Vector3.zero) { RPGCamera.Instance.RotateCameraBehindTarget = cameraRotateBehindOnMove; } // If we're holding down mouse look, lock camera if (mouseLookDown) { RPGCamera.Instance.LockCameraBehindTarget = cameraLockBehindOnMouseLook; motor.Yaw(Input.GetAxisRaw("Mouse X") * Time.smoothDeltaTime * mouseTurnSpeed); } // If we pressed mouse look, set rotation if (mouseLookPressed) { Camera cam = RPGCamera.Instance.Camera; motor.SetYaw(RPGInputUtils.SignedAngle(Vector3.forward, cam.transform.forward, Vector3.up)); } }
void Update() { forwardRunSpeed = 1f * movespeed; backwardRunSpeed = 1f * movespeed; islock = GetComponent <CameraMovement>().controlLock; motor.MovementInput = Vector3.zero; if (islock) { motor.Yaw(Input.GetAxisRaw("Mouse X") * Time.smoothDeltaTime * mouseTurnSpeed); } bool forwardKeyDown = Input.GetKey(forwardKey); bool backwardKeyDown = Input.GetKey(backwardKey); bool leftKeyDown = Input.GetKey(leftKey); bool rightKeyDown = Input.GetKey(rightKey); bool jumpKeyPressed = Input.GetKeyDown(jumpKey); //bool walkKeyDown = Input.GetKey(walkToggle); bool mouseLookDown = Input.GetMouseButton((int)mouseLookButton) && enableMouseLook; bool mouseLookPressed = Input.GetMouseButtonDown((int)mouseLookButton) && enableMouseLook; bool bothMiceDown = Input.GetMouseButton((int)mouseRunAndLookButton) && mouseLookDown && enableRunAndLook; bool autorunPressed = Input.GetMouseButtonDown((int)autorunToggleButton); //IsRunning = !walkKeyDown; MouseLook = mouseLookDown; //motor.MovementInput.z += Input.GetAxis("Vertical"); //motor.MovementInput.x += Input.GetAxis("Horizontal"); if (autorunPressed) { autorun = !autorun; } if (autorun || forwardKeyDown || bothMiceDown) { motor.MovementInput.z += 1f; } if (backwardKeyDown) { motor.MovementInput.z -= 1f; } if (leftKeyDown) { motor.MovementInput.x -= 1f; } if (rightKeyDown) { motor.MovementInput.x += 1f; } // Set movement speed //if (motor.MovementInput.z < 0) //{ // motor.MovementSpeed = walkKeyDown ? backwardWalkSpeed : backwardRunSpeed; //} //else //{ // motor.MovementSpeed = walkKeyDown ? forwardWalkSpeed : forwardRunSpeed; //} // Jump if (jumpKeyPressed) { motor.Jump(); } // Clear autorun if ((mouseLookDown && (leftKeyDown || rightKeyDown)) || forwardKeyDown || backwardKeyDown || bothMiceDown) { autorun = false; } // If we're moving, rotate camera behind us //if (motor.MovementInput != Vector3.zero) //{ // RPGCamera.Instance.RotateCameraBehindTarget = cameraRotateBehindOnMove; //} // If we're holding down mouse look, lock camera //if (mouseLookDown) //{ //RPGCamera.Instance.LockCameraBehindTarget = cameraLockBehindOnMouseLook; //} // If we pressed mouse look, set rotation //if (mouseLookPressed) //{ // //Camera cam = RPGCamera.Instance.Camera; // motor.SetYaw(RPGInputUtils.SignedAngle(Vector3.forward, cam.transform.forward, Vector3.up)); //} }