Last active
January 8, 2025 20:40
-
-
Save Plimsky/925aacdcad0e9d259f690efe562d7bdf to your computer and use it in GitHub Desktop.
Add rotation inertia to the camera of the UE Motion FPS plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void UMotionCameraComponent::GetCameraView(float DeltaTime, FMinimalViewInfo& DesiredView) | |
{ | |
// ... | |
for (const TTuple<FString, UE::Math::TRotator<double>> & StaticRotationOffset: CameraStaticRotationOffsets) | |
{ | |
UpdatedCameraRotation = FRotator(FQuat(UpdatedCameraRotation) * FQuat(StaticRotationOffset.Value)); | |
} | |
UpdatedCameraRotation = FRotator(FQuat(UpdatedCameraRotation) * FQuat(CameraRotatorFromCurves)); | |
// Apply inertia effect based on camera rotation | |
if (bFirstInitialization) | |
{ | |
CurrentRotation = UpdatedCameraRotation; | |
bFirstInitialization = false; | |
} | |
if (bEnableCameraInertia && CurrentRotation.Equals(UpdatedCameraRotation, 0.01f) == false) | |
{ | |
// Interpolate towards the target rotation | |
CurrentRotation = FMath::RInterpTo(CurrentRotation, UpdatedCameraRotation, DeltaTime, CameraInertiaStrength); | |
} | |
else | |
{ | |
CurrentRotation = UpdatedCameraRotation; | |
} | |
DesiredView.Rotation = CurrentRotation; | |
SetWorldRotation(CurrentRotation); | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MOTIONCORE_API UMotionCameraComponent : public UCameraComponent | |
{ | |
GENERATED_BODY() | |
//... | |
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Configuration") | |
float CameraInertiaStrength = 1.0f; | |
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Configuration") | |
bool bEnableCameraInertia = false; | |
UPROPERTY() | |
bool bFirstInitialization = true; | |
UPROPERTY() | |
FRotator CurrentRotation = FRotator::ZeroRotator; | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment