Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
dyanikoglu committed Dec 1, 2020
1 parent e4e07c3 commit 3c8da75
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 69 deletions.
73 changes: 50 additions & 23 deletions Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void AALSBaseCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo
PlayerInputComponent->BindAction("StanceAction", IE_Pressed, this, &AALSBaseCharacter::StancePressedAction);
PlayerInputComponent->BindAction("WalkAction", IE_Pressed, this, &AALSBaseCharacter::WalkPressedAction);
PlayerInputComponent->BindAction("RagdollAction", IE_Pressed, this, &AALSBaseCharacter::RagdollPressedAction);
PlayerInputComponent->BindAction("SelectRotationMode_1", IE_Pressed, this, &AALSBaseCharacter::VelocityDirectionPressedAction);
PlayerInputComponent->BindAction("SelectRotationMode_2", IE_Pressed, this, &AALSBaseCharacter::LookingDirectionPressedAction);
PlayerInputComponent->BindAction("SelectRotationMode_1", IE_Pressed, this,
&AALSBaseCharacter::VelocityDirectionPressedAction);
PlayerInputComponent->BindAction("SelectRotationMode_2", IE_Pressed, this,
&AALSBaseCharacter::LookingDirectionPressedAction);
PlayerInputComponent->BindAction("SprintAction", IE_Pressed, this, &AALSBaseCharacter::SprintPressedAction);
PlayerInputComponent->BindAction("SprintAction", IE_Released, this, &AALSBaseCharacter::SprintReleasedAction);
PlayerInputComponent->BindAction("AimAction", IE_Pressed, this, &AALSBaseCharacter::AimPressedAction);
Expand Down Expand Up @@ -478,13 +480,15 @@ void AALSBaseCharacter::EventOnJumped()
MainAnimInstance->OnJumped();
}

void AALSBaseCharacter::Server_MantleStart_Implementation(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS,
void AALSBaseCharacter::Server_MantleStart_Implementation(float MantleHeight,
const FALSComponentAndTransform& MantleLedgeWS,
EALSMantleType MantleType)
{
Multicast_MantleStart(MantleHeight, MantleLedgeWS, MantleType);
}

void AALSBaseCharacter::Multicast_MantleStart_Implementation(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS,
void AALSBaseCharacter::Multicast_MantleStart_Implementation(float MantleHeight,
const FALSComponentAndTransform& MantleLedgeWS,
EALSMantleType MantleType)
{
if (!IsLocallyControlled())
Expand Down Expand Up @@ -695,18 +699,23 @@ void AALSBaseCharacter::GetCameraParameters(float& TPFOVOut, float& FPFOVOut, bo

void AALSBaseCharacter::SetAcceleration(const FVector& NewAcceleration)
{
Acceleration = (NewAcceleration != FVector::ZeroVector || IsLocallyControlled()) ? NewAcceleration : Acceleration / 2;
Acceleration = (NewAcceleration != FVector::ZeroVector || IsLocallyControlled())
? NewAcceleration
: Acceleration / 2;
MainAnimInstance->GetCharacterInformationMutable().Acceleration = Acceleration;
}

void AALSBaseCharacter::RagdollUpdate(float DeltaTime)
{
// Set the Last Ragdoll Velocity.
FVector NewRagdollVel = GetMesh()->GetPhysicsLinearVelocity(FName(TEXT("root")));
LastRagdollVelocity = (NewRagdollVel != FVector::ZeroVector || IsLocallyControlled()) ? NewRagdollVel : LastRagdollVelocity / 2;
LastRagdollVelocity = (NewRagdollVel != FVector::ZeroVector || IsLocallyControlled())
? NewRagdollVel
: LastRagdollVelocity / 2;

// Use the Ragdoll Velocity to scale the ragdoll's joint strength for physical animation.
const float SpringValue = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 25000.0f}, LastRagdollVelocity.Size());
const float SpringValue = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 25000.0f},
LastRagdollVelocity.Size());
GetMesh()->SetAllMotorsAngularDriveParams(SpringValue, 0.0f, 0.0f, false);

// Disable Gravity if falling faster than -4000 to prevent continual acceleration.
Expand Down Expand Up @@ -762,8 +771,9 @@ void AALSBaseCharacter::SetActorLocationDuringRagdoll(float DeltaTime)
ServerRagdollPull = FMath::FInterpTo(ServerRagdollPull, 750, DeltaTime, 0.6);
float RagdollSpeed = FVector(LastRagdollVelocity.X, LastRagdollVelocity.Y, 0).Size();
FName RagdollSocketPullName = RagdollSpeed > 300 ? FName(TEXT("spine_03")) : FName(TEXT("pelvis"));
GetMesh()->AddForce((TargetRagdollLocation - GetMesh()->GetSocketLocation(RagdollSocketPullName)) * ServerRagdollPull,
RagdollSocketPullName, true);
GetMesh()->AddForce(
(TargetRagdollLocation - GetMesh()->GetSocketLocation(RagdollSocketPullName)) * ServerRagdollPull,
RagdollSocketPullName, true);
}
SetActorLocationAndTargetRotation(bRagdollOnGround ? NewRagdollLoc : TargetRagdollLocation, TargetRagdollRotation);
}
Expand Down Expand Up @@ -1053,7 +1063,8 @@ void AALSBaseCharacter::UpdateGroundedRotation(float DeltaTime)
if (RotationMode == EALSRotationMode::VelocityDirection)
{
// Velocity Direction Rotation
SmoothCharacterRotation({0.0f, LastVelocityRotation.Yaw, 0.0f}, 800.0f, GroundedRotationRate, DeltaTime);
SmoothCharacterRotation({0.0f, LastVelocityRotation.Yaw, 0.0f}, 800.0f, GroundedRotationRate,
DeltaTime);
}
else if (RotationMode == EALSRotationMode::LookingDirection)
{
Expand Down Expand Up @@ -1137,7 +1148,8 @@ void AALSBaseCharacter::UpdateInAirRotation(float DeltaTime)
}
}

void AALSBaseCharacter::MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, EALSMantleType MantleType)
void AALSBaseCharacter::MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS,
EALSMantleType MantleType)
{
// Step 1: Get the Mantle Asset and use it to set the new Mantle Params.
const FALSMantleAsset& MantleAsset = GetMantleAsset(MantleType);
Expand All @@ -1146,10 +1158,14 @@ void AALSBaseCharacter::MantleStart(float MantleHeight, const FALSComponentAndTr
MantleParams.PositionCorrectionCurve = MantleAsset.PositionCorrectionCurve;
MantleParams.StartingOffset = MantleAsset.StartingOffset;
MantleParams.StartingPosition = FMath::GetMappedRangeValueClamped({MantleAsset.LowHeight, MantleAsset.HighHeight},
{MantleAsset.LowStartPosition, MantleAsset.HighStartPosition},
{
MantleAsset.LowStartPosition,
MantleAsset.HighStartPosition
},
MantleHeight);
MantleParams.PlayRate = FMath::GetMappedRangeValueClamped({MantleAsset.LowHeight, MantleAsset.HighHeight},
{MantleAsset.LowPlayRate, MantleAsset.HighPlayRate}, MantleHeight);
{MantleAsset.LowPlayRate, MantleAsset.HighPlayRate},
MantleHeight);

// Step 2: Convert the world space target to the mantle component's local space for use in moving objects.
MantleLedgeLS.Component = MantleLedgeWS.Component;
Expand Down Expand Up @@ -1227,7 +1243,8 @@ bool AALSBaseCharacter::MantleCheck(const FALSMantleTraceSettings& TraceSettings
DownwardTraceStart.Z += TraceSettings.MaxLedgeHeight + TraceSettings.DownwardTraceRadius + 1.0f;

World->SweepSingleByChannel(HitResult, DownwardTraceStart, DownwardTraceEnd, FQuat::Identity,
ECC_GameTraceChannel2, FCollisionShape::MakeSphere(TraceSettings.DownwardTraceRadius), Params);
ECC_GameTraceChannel2, FCollisionShape::MakeSphere(TraceSettings.DownwardTraceRadius),
Params);


if (!GetCharacterMovement()->IsWalkable(HitResult))
Expand All @@ -1241,7 +1258,8 @@ bool AALSBaseCharacter::MantleCheck(const FALSMantleTraceSettings& TraceSettings

// Step 3: Check if the capsule has room to stand at the downward trace's location.
// If so, set that location as the Target Transform and calculate the mantle height.
const FVector& CapsuleLocationFBase = UALSMathLibrary::GetCapsuleLocationFromBase(DownTraceLocation, 2.0f, GetCapsuleComponent());
const FVector& CapsuleLocationFBase = UALSMathLibrary::GetCapsuleLocationFromBase(
DownTraceLocation, 2.0f, GetCapsuleComponent());
const bool bCapsuleHasRoom = UALSMathLibrary::CapsuleHasRoomCheck(GetCapsuleComponent(), CapsuleLocationFBase, 0.0f,
0.0f);

Expand Down Expand Up @@ -1287,7 +1305,8 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn)

// Step 2: Update the Position and Correction Alphas using the Position/Correction curve set for each Mantle.
const FVector CurveVec = MantleParams.PositionCorrectionCurve
->GetVectorValue(MantleParams.StartingPosition + MantleTimeline->GetPlaybackPosition());
->GetVectorValue(
MantleParams.StartingPosition + MantleTimeline->GetPlaybackPosition());
const float PositionAlpha = CurveVec.X;
const float XYCorrectionAlpha = CurveVec.Y;
const float ZCorrectionAlpha = CurveVec.Z;
Expand All @@ -1298,7 +1317,8 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn)
// Blend into the animated horizontal and rotation offset using the Y value of the Position/Correction Curve.
const FTransform TargetHzTransform(MantleAnimatedStartOffset.GetRotation(),
{
MantleAnimatedStartOffset.GetLocation().X, MantleAnimatedStartOffset.GetLocation().Y,
MantleAnimatedStartOffset.GetLocation().X,
MantleAnimatedStartOffset.GetLocation().Y,
MantleActualStartOffset.GetLocation().Z
},
FVector::OneVector);
Expand All @@ -1308,26 +1328,32 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn)
// Blend into the animated vertical offset using the Z value of the Position/Correction Curve.
const FTransform TargetVtTransform(MantleActualStartOffset.GetRotation(),
{
MantleActualStartOffset.GetLocation().X, MantleActualStartOffset.GetLocation().Y,
MantleActualStartOffset.GetLocation().X,
MantleActualStartOffset.GetLocation().Y,
MantleAnimatedStartOffset.GetLocation().Z
},
FVector::OneVector);
const FTransform& VtLerpResult =
UKismetMathLibrary::TLerp(MantleActualStartOffset, TargetVtTransform, ZCorrectionAlpha);

const FTransform ResultTransform(HzLerpResult.GetRotation(),
{HzLerpResult.GetLocation().X, HzLerpResult.GetLocation().Y, VtLerpResult.GetLocation().Z},
{
HzLerpResult.GetLocation().X, HzLerpResult.GetLocation().Y,
VtLerpResult.GetLocation().Z
},
FVector::OneVector);

// Blend from the currently blending transforms into the final mantle target using the X
// value of the Position/Correction Curve.
const FTransform& ResultLerp = UKismetMathLibrary::TLerp(UALSMathLibrary::TransfromAdd(MantleTarget, ResultTransform), MantleTarget,
PositionAlpha);
const FTransform& ResultLerp = UKismetMathLibrary::TLerp(
UALSMathLibrary::TransfromAdd(MantleTarget, ResultTransform), MantleTarget,
PositionAlpha);

// Initial Blend In (controlled in the timeline curve) to allow the actor to blend into the Position/Correction
// curve at the midoint. This prevents pops when mantling an object lower than the animated mantle.
const FTransform& LerpedTarget =
UKismetMathLibrary::TLerp(UALSMathLibrary::TransfromAdd(MantleTarget, MantleActualStartOffset), ResultLerp, BlendIn);
UKismetMathLibrary::TLerp(UALSMathLibrary::TransfromAdd(MantleTarget, MantleActualStartOffset), ResultLerp,
BlendIn);

// Step 4: Set the actors location and rotation to the Lerped Target.
SetActorLocationAndTargetRotation(LerpedTarget.GetLocation(), LerpedTarget.GetRotation().Rotator());
Expand Down Expand Up @@ -1485,7 +1511,8 @@ void AALSBaseCharacter::PlayerRightMovementInput(float Value)
if (MovementState == EALSMovementState::Grounded || MovementState == EALSMovementState::InAir)
{
// Default camera relative movement behavior
const float Scale = UALSMathLibrary::FixDiagonalGamepadValues(GetInputAxisValue("MoveForward/Backwards"), Value).Value;
const float Scale = UALSMathLibrary::FixDiagonalGamepadValues(GetInputAxisValue("MoveForward/Backwards"), Value)
.Value;
const FRotator DirRotator(0.0f, AimingRotation.Yaw, 0.0f);
AddMovementInput(UKismetMathLibrary::GetRightVector(DirRotator), Scale);
}
Expand Down
30 changes: 20 additions & 10 deletions Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void AALSPlayerCameraManager::UpdateViewTargetInternal(FTViewTarget& OutVT, floa
}

FVector AALSPlayerCameraManager::CalculateAxisIndependentLag(FVector CurrentLocation, FVector TargetLocation,
FRotator CameraRotation, FVector LagSpeeds, float DeltaTime)
FRotator CameraRotation, FVector LagSpeeds,
float DeltaTime)
{
CameraRotation.Roll = 0.0f;
CameraRotation.Pitch = 0.0f;
Expand Down Expand Up @@ -115,7 +116,8 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc
GetCameraBehaviorParam(FName(TEXT("PivotLagSpeed_Z"))));

const FVector& AxisIndpLag = CalculateAxisIndependentLag(SmoothedPivotTarget.GetLocation(),
PivotTarget.GetLocation(), TargetCameraRotation, LagSpd, DeltaTime);
PivotTarget.GetLocation(), TargetCameraRotation, LagSpd,
DeltaTime);

SmoothedPivotTarget.SetRotation(PivotTarget.GetRotation());
SmoothedPivotTarget.SetLocation(AxisIndpLag);
Expand All @@ -125,15 +127,20 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc
// Pivot Target and apply local offsets for further camera control.
PivotLocation =
SmoothedPivotTarget.GetLocation() +
UKismetMathLibrary::GetForwardVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam(FName(TEXT("PivotOffset_X"))) +
UKismetMathLibrary::GetRightVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam(FName(TEXT("PivotOffset_Y"))) +
UKismetMathLibrary::GetUpVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam(FName(TEXT("PivotOffset_Z")));
UKismetMathLibrary::GetForwardVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam(
FName(TEXT("PivotOffset_X"))) +
UKismetMathLibrary::GetRightVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam(
FName(TEXT("PivotOffset_Y"))) +
UKismetMathLibrary::GetUpVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam(
FName(TEXT("PivotOffset_Z")));

// Step 5: Calculate Target Camera Location. Get the Pivot location and apply camera relative offsets.
TargetCameraLocation = UKismetMathLibrary::VLerp(
PivotLocation +
UKismetMathLibrary::GetForwardVector(TargetCameraRotation) * GetCameraBehaviorParam(FName(TEXT("CameraOffset_X"))) +
UKismetMathLibrary::GetRightVector(TargetCameraRotation) * GetCameraBehaviorParam(FName(TEXT("CameraOffset_Y"))) +
UKismetMathLibrary::GetForwardVector(TargetCameraRotation) * GetCameraBehaviorParam(
FName(TEXT("CameraOffset_X"))) +
UKismetMathLibrary::GetRightVector(TargetCameraRotation) * GetCameraBehaviorParam(FName(TEXT("CameraOffset_Y")))
+
UKismetMathLibrary::GetUpVector(TargetCameraRotation) * GetCameraBehaviorParam(FName(TEXT("CameraOffset_Z"))),
PivotTarget.GetLocation() + DebugViewOffset,
GetCameraBehaviorParam(FName(TEXT("Override_Debug"))));
Expand Down Expand Up @@ -169,11 +176,14 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc
FTransform FPTargetCameraTransform(TargetCameraRotation, FPTarget, FVector::OneVector);

const FTransform& MixedTransform = UKismetMathLibrary::TLerp(TargetCameraTransform, FPTargetCameraTransform,
GetCameraBehaviorParam(FName(TEXT("Weight_FirstPerson"))));
GetCameraBehaviorParam(
FName(TEXT("Weight_FirstPerson"))));

const FTransform& TargetTransform = UKismetMathLibrary::TLerp(MixedTransform,
FTransform(DebugViewRotation, TargetCameraLocation, FVector::OneVector),
GetCameraBehaviorParam(FName(TEXT("Override_Debug"))));
FTransform(DebugViewRotation, TargetCameraLocation,
FVector::OneVector),
GetCameraBehaviorParam(
FName(TEXT("Override_Debug"))));

Location = TargetTransform.GetLocation();
Rotation = TargetTransform.Rotator();
Expand Down
Loading

0 comments on commit 3c8da75

Please sign in to comment.