Skip to content

Various fixes on the camera modifier to update the Z of the camera wh… #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <Engine/Canvas.h>
#include <GameFramework/Character.h>
#include <GameFramework/CharacterMovementComponent.h>
#include <GameFramework/SpringArmComponent.h>

UGBFCameraModifierJumpZ::UGBFCameraModifierJumpZ() :
LandingTransitionTime( 0.5f ),
LandOnSameHeightCheckTolerance( 1.0f ),
Expand All @@ -17,8 +15,7 @@ UGBFCameraModifierJumpZ::UGBFCameraModifierJumpZ() :
CurrentCameraZPosition( 0.0f ),
LerpStartCameraZPosition( 0.0f ),
LerpEndCameraZPosition( 0.0f ),
LandingTransitionRemainingTime( 0.0f ),
bShouldInterpolateWhenJumping( false )
LandingTransitionRemainingTime( 0.0f )
{
}

Expand Down Expand Up @@ -64,29 +61,19 @@ void UGBFCameraModifierJumpZ::ModifyCamera( float delta_time, FVector view_locat
{
if ( cmc->MovementMode == MOVE_Walking )
{
bShouldInterpolateWhenJumping = false;
CurrentState = EState::Landing;
LandingTransitionRemainingTime = LandingTransitionTime;

if ( FMath::IsNearlyEqual( CurrentCharacterZPosition, LastGroundedCharacterZPosition, LandOnSameHeightCheckTolerance ) )
{
LerpStartCameraZPosition = LastGroundedCameraZPosition;
}
else
{
LerpStartCameraZPosition = LastGroundedCameraZPosition;
}
LerpStartCameraZPosition = LastGroundedCameraZPosition;
}

if ( character->GetVelocity().Z <= 0.0f && CurrentCharacterZPosition < LastGroundedCharacterZPosition - DistanceFromLastGroundedPositionToResetModifier )
{
CurrentState = EState::WaitingForJump;
bShouldInterpolateWhenJumping = false;
return;
}

const auto offset = bShouldInterpolateWhenJumping ? DeltaLastGroundedCharacterToCameraZ : 0.0f;
new_view_location.Z = FMath::FInterpTo( new_view_location.Z, LastGroundedCameraZPosition + offset, delta_time, 2.0f );
new_view_location.Z = LastGroundedCameraZPosition;
}
break;
case EState::Landing:
Expand All @@ -95,8 +82,7 @@ void UGBFCameraModifierJumpZ::ModifyCamera( float delta_time, FVector view_locat
{
CurrentState = EState::Jumping;
LastGroundedCharacterZPosition = CurrentCharacterZPosition;
LastGroundedCameraZPosition = view_location.Z;
bShouldInterpolateWhenJumping = true;
LastGroundedCameraZPosition = CurrentCameraZPosition;
}
else
{
Expand All @@ -109,7 +95,15 @@ void UGBFCameraModifierJumpZ::ModifyCamera( float delta_time, FVector view_locat
}
else
{
LerpEndCameraZPosition = view_location.Z;
if ( FMath::Abs( CurrentCharacterZPosition - LastGroundedCharacterZPosition ) >= DistanceFromLastGroundedPositionToResetModifier )
{
LerpEndCameraZPosition = view_location.Z;
}
else
{
LerpEndCameraZPosition = LastGroundedCameraZPosition;
}

new_view_location.Z = FMath::Lerp( LerpStartCameraZPosition, LerpEndCameraZPosition, 1.0f - ( LandingTransitionRemainingTime / LandingTransitionTime ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ class GAMEBASEFRAMEWORK_API UGBFCameraModifierJumpZ final : public UGBFCameraMod
float LerpStartCameraZPosition;
float LerpEndCameraZPosition;
float LandingTransitionRemainingTime;
bool bShouldInterpolateWhenJumping;
};