Hello, I’m having difficulty disabling the player/player camera from rotating when the player moves the mouse. I am using the C++ FPS Template. Basically all I am trying to achieve is for when the player presses “Q” the mouse no longer rotates the player/player camera. This is what I have so far in the character class.
void AASF_PrototypeCharacter::TurnAtRate(float Rate)
{
// calculate delta for this frame from the rate information
if (bCameraMovement == true) {
AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
}
else {
AddControllerYawInput(0);
}
}
void AASF_PrototypeCharacter::LookUpAtRate(float Rate)
{
// calculate delta for this frame from the rate information
if (bCameraMovement == true) {
AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
}
else {
AddControllerPitchInput(0);
}
}
bCameraMovement is a boolean that is changed when the player presses and releases “Q”, which is working as I’ve done debugging. Any tips/hints on what to do is welcomed, and I can post more of the code if needed.
When you release the Q button your bCameraMovement is set back to true. This means you will enter the if statement’s body and you’ll have pitch and yaw control.
Yeah I’m not sure what is going on. I’ve completely disabled the TurnAtRate and LookUpAtRate functions and my player still rotates with mouse movement. Seems like the player is being rotated somewhere else but I can’t find it.
Your Mouse controlled camera functions are using the built in functions AddControllerYawInput() and AddControllerPitchInput(). The TurnAtRate() and LookUpAtRate() functions are being used for a controller or your arrow keys.
Now if you were to check if(bCameraMovement) it should work. Note: I noticed in project settings->input->Axis Mapping->Look Up->Mouse Y is set to -1. This means the mouse is inverted by default. Either get rid of n8MouseInvertion, set n8MouseInvertion to 1 or set Look Up->Mouse Y in project settings to 1.0.
lol I can’t believe I didn’t notice I was just turning off the rotation for controllers. Thanks a lot! And and extra thank you for creating that nice little tutorial.
Why reinvent the wheel when you don’t have to? Rather than rewriting Camera functions you can just set the Pitch, Yaw, and Roll in the player control to Zero and then reset to the previous values.
This is just an example in Blueprints, but I’d imagine it’d be pretty similar in C++.