From ad4e14e30eb8981552b2698181df552577fc9fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Fri, 6 Nov 2020 12:31:33 +0300 Subject: [PATCH 1/9] Remove duplicate call on ragdoll update --- Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index ae9015e4..a35f1f1c 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -704,7 +704,6 @@ 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()); From 40a96b5d9a7e02f5e855cf6164a7e65101a3791b Mon Sep 17 00:00:00 2001 From: Sebastien <34646501+seb-exiin@users.noreply.github.com> Date: Fri, 20 Nov 2020 10:56:31 +0100 Subject: [PATCH 2/9] Add comments to explain MantleUpdate (#86) --- Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index a35f1f1c..c84f6c6b 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -1279,6 +1279,7 @@ bool AALSBaseCharacter::MantleCheck(const FALSMantleTraceSettings& TraceSettings return true; } +// This function is called by "MantleTimeline" using BindUFunction in the AALSBaseCharacter::BeginPlay during the default settings initalization. void AALSBaseCharacter::MantleUpdate(float BlendIn) { // Step 1: Continually update the mantle target from the stored local transform to follow along with moving objects From e4e07c34731d6c9ec2a49d2fe8ef2bf399189de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Wed, 2 Dec 2020 00:31:11 +0300 Subject: [PATCH 3/9] Fix foot IK issues on packaged game, because of corrupt data on offset target vectors --- .../Private/Character/Animation/ALSCharacterAnimInstance.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp index a676c477..94f30a38 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp @@ -257,8 +257,9 @@ void UALSCharacterAnimInstance::UpdateLayerValues() void UALSCharacterAnimInstance::UpdateFootIK(float DeltaSeconds) { - FVector FootOffsetLTarget; - FVector FootOffsetRTarget; + FVector FootOffsetLTarget = FVector::ZeroVector; + FVector FootOffsetRTarget = FVector::ZeroVector; + // Update Foot Locking values. SetFootLocking(DeltaSeconds, FName(TEXT("Enable_FootIK_L")), FName(TEXT("FootLock_L")), FName(TEXT("ik_foot_l")), FootIKValues.FootLock_L_Alpha, FootIKValues.UseFootLockCurve_L, From 3c8da758f3efe7e3c118d58349495ea9c7c54b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Wed, 2 Dec 2020 00:32:36 +0300 Subject: [PATCH 4/9] Reformat code --- .../Private/Character/ALSBaseCharacter.cpp | 73 +++++++++++++------ .../Character/ALSPlayerCameraManager.cpp | 30 +++++--- .../Animation/ALSCharacterAnimInstance.cpp | 57 ++++++++++----- .../Private/Library/ALSMathLibrary.cpp | 6 +- .../Public/Character/ALSBaseCharacter.h | 20 +++-- .../Animation/ALSCharacterAnimInstance.h | 22 ++++-- .../ALSV4_CPP/Public/Library/ALSMathLibrary.h | 3 +- 7 files changed, 142 insertions(+), 69 deletions(-) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index c84f6c6b..ac57b134 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -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); @@ -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()) @@ -695,7 +699,9 @@ 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; } @@ -703,10 +709,13 @@ 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. @@ -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); } @@ -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) { @@ -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); @@ -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; @@ -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)) @@ -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); @@ -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; @@ -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); @@ -1308,7 +1328,8 @@ 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); @@ -1316,18 +1337,23 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn) 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()); @@ -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); } diff --git a/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp b/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp index e60bf3f3..246dc443 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp @@ -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; @@ -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); @@ -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")))); @@ -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(); diff --git a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp index 94f30a38..1d6f7f32 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp @@ -196,7 +196,8 @@ void UALSCharacterAnimInstance::UpdateAimingValues(float DeltaSeconds) if (!RotationMode.VelocityDirection()) { // Clamp the Aiming Pitch Angle to a range of 1 to 0 for use in the vertical aim sweeps. - AimingValues.AimSweepTime = FMath::GetMappedRangeValueClamped({-90.0f, 90.0f}, {1.0f, 0.0f}, AimingValues.AimingAngle.Y); + AimingValues.AimSweepTime = FMath::GetMappedRangeValueClamped({-90.0f, 90.0f}, {1.0f, 0.0f}, + AimingValues.AimingAngle.Y); // Use the Aiming Yaw Angle divided by the number of spine+pelvis bones to get the amount of spine rotation // needed to remain facing the camera direction. @@ -277,9 +278,11 @@ void UALSCharacterAnimInstance::UpdateFootIK(float DeltaSeconds) else if (!MovementState.Ragdoll()) { // Update all Foot Lock and Foot Offset values when not In Air - SetFootOffsets(DeltaSeconds, FName(TEXT("Enable_FootIK_L")), FName(TEXT("ik_foot_l")), FName(TEXT("root")), FootOffsetLTarget, + SetFootOffsets(DeltaSeconds, FName(TEXT("Enable_FootIK_L")), FName(TEXT("ik_foot_l")), FName(TEXT("root")), + FootOffsetLTarget, FootIKValues.FootOffset_L_Location, FootIKValues.FootOffset_L_Rotation); - SetFootOffsets(DeltaSeconds, FName(TEXT("Enable_FootIK_R")), FName(TEXT("ik_foot_r")), FName(TEXT("root")), FootOffsetRTarget, + SetFootOffsets(DeltaSeconds, FName(TEXT("Enable_FootIK_R")), FName(TEXT("ik_foot_r")), FName(TEXT("root")), + FootOffsetRTarget, FootIKValues.FootOffset_R_Location, FootIKValues.FootOffset_R_Rotation); SetPelvisIKOffset(DeltaSeconds, FootOffsetLTarget, FootOffsetRTarget); } @@ -340,7 +343,8 @@ void UALSCharacterAnimInstance::SetFootLockOffsets(float DeltaSeconds, FVector& // to remain planted on the ground. if (Character->GetCharacterMovement()->IsMovingOnGround()) { - RotationDifference = CharacterInformation.CharacterActorRotation - Character->GetCharacterMovement()->GetLastUpdateRotation(); + RotationDifference = CharacterInformation.CharacterActorRotation - Character->GetCharacterMovement()-> + GetLastUpdateRotation(); RotationDifference.Normalize(); } @@ -462,9 +466,10 @@ void UALSCharacterAnimInstance::RotateInPlaceCheck() // This makes the character rotate faster when moving the camera faster. if (Grounded.bRotateL || Grounded.bRotateR) { - Grounded.RotateRate = FMath::GetMappedRangeValueClamped({RotateInPlace.AimYawRateMinRange, RotateInPlace.AimYawRateMaxRange}, - {RotateInPlace.MinPlayRate, RotateInPlace.MaxPlayRate}, - CharacterInformation.AimYawRate); + Grounded.RotateRate = FMath::GetMappedRangeValueClamped( + {RotateInPlace.AimYawRateMinRange, RotateInPlace.AimYawRateMaxRange}, + {RotateInPlace.MinPlayRate, RotateInPlace.MaxPlayRate}, + CharacterInformation.AimYawRate); } } @@ -482,7 +487,10 @@ void UALSCharacterAnimInstance::TurnInPlaceCheck(float DeltaSeconds) TurnInPlaceValues.ElapsedDelayTime += DeltaSeconds; const float ClampedAimAngle = FMath::GetMappedRangeValueClamped({TurnInPlaceValues.TurnCheckMinAngle, 180.0f}, - {TurnInPlaceValues.MinAngleDelay, TurnInPlaceValues.MaxAngleDelay}, + { + TurnInPlaceValues.MinAngleDelay, + TurnInPlaceValues.MaxAngleDelay + }, AimingValues.AimingAngle.X); // Step 2: Check if the Elapsed Delay time exceeds the set delay (mapped to the turn angle range). If so, trigger a Turn In Place. @@ -502,7 +510,8 @@ void UALSCharacterAnimInstance::DynamicTransitionCheck() // The currently set transition plays the second half of a 2 foot transition animation, so that only a single foot moves. // Because only the IK_Foot bone can be locked, the separate virtual bone allows the system to know its desired location when locked. FTransform SocketTransformA = GetOwningComponent()->GetSocketTransform(FName(TEXT("ik_foot_l")), RTS_Component); - FTransform SocketTransformB = GetOwningComponent()->GetSocketTransform(FName(TEXT("VB foot_target_l")), RTS_Component); + FTransform SocketTransformB = GetOwningComponent()->GetSocketTransform( + FName(TEXT("VB foot_target_l")), RTS_Component); float Distance = (SocketTransformB.GetLocation() - SocketTransformA.GetLocation()).Size(); if (Distance > Config.DynamicTransitionThreshold) { @@ -544,8 +553,10 @@ void UALSCharacterAnimInstance::UpdateMovementValues(float DeltaSeconds) // Set the Relative Acceleration Amount and Interp the Lean Amount. RelativeAccelerationAmount = CalculateRelativeAccelerationAmount(); - LeanAmount.LR = FMath::FInterpTo(LeanAmount.LR, RelativeAccelerationAmount.Y, DeltaSeconds, Config.GroundedLeanInterpSpeed); - LeanAmount.FB = FMath::FInterpTo(LeanAmount.FB, RelativeAccelerationAmount.X, DeltaSeconds, Config.GroundedLeanInterpSpeed); + LeanAmount.LR = FMath::FInterpTo(LeanAmount.LR, RelativeAccelerationAmount.Y, DeltaSeconds, + Config.GroundedLeanInterpSpeed); + LeanAmount.FB = FMath::FInterpTo(LeanAmount.FB, RelativeAccelerationAmount.X, DeltaSeconds, + Config.GroundedLeanInterpSpeed); // Set the Walk Run Blend Grounded.WalkRunBlend = CalculateWalkRunBlend(); @@ -598,7 +609,8 @@ void UALSCharacterAnimInstance::UpdateRagdollValues() FlailRate = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 1.0f}, VelocityLength); } -float UALSCharacterAnimInstance::GetAnimCurveClamped(const FName& Name, float Bias, float ClampMin, float ClampMax) const +float UALSCharacterAnimInstance::GetAnimCurveClamped(const FName& Name, float Bias, float ClampMin, + float ClampMax) const { return FMath::Clamp(GetCurveValue(Name) + Bias, ClampMin, ClampMax); } @@ -649,7 +661,8 @@ float UALSCharacterAnimInstance::CalculateStrideBlend() const const float CurveTime = CharacterInformation.Speed / GetOwningComponent()->GetComponentScale().Z; const float ClampedGait = GetAnimCurveClamped(FName(TEXT("Weight_Gait")), -1.0, 0.0f, 1.0f); const float LerpedStrideBlend = - FMath::Lerp(StrideBlend_N_Walk->GetFloatValue(CurveTime), StrideBlend_N_Run->GetFloatValue(CurveTime), ClampedGait); + FMath::Lerp(StrideBlend_N_Walk->GetFloatValue(CurveTime), StrideBlend_N_Run->GetFloatValue(CurveTime), + ClampedGait); return FMath::Lerp(LerpedStrideBlend, StrideBlend_C_Walk->GetFloatValue(CharacterInformation.Speed), GetCurveValue(FName(TEXT("BasePose_CLF")))); } @@ -673,7 +686,8 @@ float UALSCharacterAnimInstance::CalculateStandingPlayRate() const const float SprintAffectedSpeed = FMath::Lerp(LerpedSpeed, CharacterInformation.Speed / Config.AnimatedSprintSpeed, GetAnimCurveClamped(FName(TEXT("Weight_Gait")), -2.0f, 0.0f, 1.0f)); - return FMath::Clamp((SprintAffectedSpeed / Grounded.StrideBlend) / GetOwningComponent()->GetComponentScale().Z, 0.0f, 3.0f); + return FMath::Clamp((SprintAffectedSpeed / Grounded.StrideBlend) / GetOwningComponent()->GetComponentScale().Z, + 0.0f, 3.0f); } float UALSCharacterAnimInstance::CalculateDiagonalScaleAmount() const @@ -689,7 +703,8 @@ float UALSCharacterAnimInstance::CalculateCrouchingPlayRate() const // Calculate the Crouching Play Rate by dividing the Character's speed by the Animated Speed. // This value needs to be separate from the standing play rate to improve the blend from crocuh to stand while in motion. return FMath::Clamp( - CharacterInformation.Speed / Config.AnimatedCrouchSpeed / Grounded.StrideBlend / GetOwningComponent()->GetComponentScale().Z, + CharacterInformation.Speed / Config.AnimatedCrouchSpeed / Grounded.StrideBlend / GetOwningComponent()-> + GetComponentScale().Z, 0.0f, 2.0f); } @@ -710,7 +725,8 @@ float UALSCharacterAnimInstance::CalculateLandPrediction() const VelocityClamped.Z = FMath::Clamp(VelocityZ, -4000.0f, -200.0f); VelocityClamped.Normalize(); - const FVector TraceLength = VelocityClamped * FMath::GetMappedRangeValueClamped({0.0f, -4000.0f}, {50.0f, 2000.0f}, VelocityZ); + const FVector TraceLength = VelocityClamped * FMath::GetMappedRangeValueClamped( + {0.0f, -4000.0f}, {50.0f, 2000.0f}, VelocityZ); UWorld* World = GetWorld(); check(World); @@ -720,13 +736,15 @@ float UALSCharacterAnimInstance::CalculateLandPrediction() const FHitResult HitResult; - World->SweepSingleByProfile(HitResult, CapsuleWorldLoc, CapsuleWorldLoc + TraceLength, FQuat::Identity, FName(TEXT("ALS_Character")), + World->SweepSingleByProfile(HitResult, CapsuleWorldLoc, CapsuleWorldLoc + TraceLength, FQuat::Identity, + FName(TEXT("ALS_Character")), FCollisionShape::MakeCapsule(CapsuleComp->GetUnscaledCapsuleRadius(), CapsuleComp->GetUnscaledCapsuleHalfHeight()), Params); if (Character->GetCharacterMovement()->IsWalkable(HitResult)) { - return FMath::Lerp(LandPredictionCurve->GetFloatValue(HitResult.Time), 0.0f, GetCurveValue(FName(TEXT("Mask_LandPrediction")))); + return FMath::Lerp(LandPredictionCurve->GetFloatValue(HitResult.Time), 0.0f, + GetCurveValue(FName(TEXT("Mask_LandPrediction")))); } return 0.0f; @@ -738,7 +756,8 @@ FALSLeanAmount UALSCharacterAnimInstance::CalculateAirLeanAmount() const // The Lean In Air curve gets the Fall Speed and is used as a multiplier to smoothly reverse the leaning direction // when transitioning from moving upwards to moving downwards. FALSLeanAmount CalcLeanAmount; - const FVector& UnrotatedVel = CharacterInformation.CharacterActorRotation.UnrotateVector(CharacterInformation.Velocity) / 350.0f; + const FVector& UnrotatedVel = CharacterInformation.CharacterActorRotation.UnrotateVector( + CharacterInformation.Velocity) / 350.0f; FVector2D InversedVect(UnrotatedVel.Y, UnrotatedVel.X); InversedVect *= LeanInAirCurve->GetFloatValue(InAir.FallSpeed); CalcLeanAmount.LR = InversedVect.X; diff --git a/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp b/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp index 02152cdd..94e2bc3c 100644 --- a/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp +++ b/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp @@ -77,8 +77,10 @@ bool UALSMathLibrary::AngleInRange(float Angle, float MinAngle, float MaxAngle, return Angle >= MinAngle + Buffer && Angle <= MaxAngle - Buffer; } -EALSMovementDirection UALSMathLibrary::CalculateQuadrant(EALSMovementDirection Current, float FRThreshold, float FLThreshold, - float BRThreshold, float BLThreshold, float Buffer, float Angle) +EALSMovementDirection UALSMathLibrary::CalculateQuadrant(EALSMovementDirection Current, float FRThreshold, + float FLThreshold, + float BRThreshold, float BLThreshold, float Buffer, + float Angle) { // Take the input angle and determine its quadrant (direction). Use the current Movement Direction to increase or // decrease the buffers on the angle ranges for each quadrant. diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index d17eda14..30423998 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -36,7 +36,10 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter AALSBaseCharacter(const FObjectInitializer& ObjectInitializer); UFUNCTION(BlueprintCallable, Category= "Movement") - FORCEINLINE class UALSCharacterMovementComponent* GetMyMovementComponent() const { return MyCharacterMovementComponent; } + FORCEINLINE class UALSCharacterMovementComponent* GetMyMovementComponent() const + { + return MyCharacterMovementComponent; + } virtual void Tick(float DeltaTime) override; @@ -153,10 +156,12 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Mantling*/ UFUNCTION(BlueprintCallable, Server, Reliable, Category = "ALS|Character States") - void Server_MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, EALSMantleType MantleType); + void Server_MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, + EALSMantleType MantleType); UFUNCTION(BlueprintCallable, NetMulticast, Reliable, Category = "ALS|Character States") - void Multicast_MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, EALSMantleType MantleType); + void Multicast_MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, + EALSMantleType MantleType); /** Ragdolling*/ UFUNCTION(BlueprintCallable, Category = "ALS|Character States") @@ -376,7 +381,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Mantle System */ - virtual void MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, EALSMantleType MantleType); + virtual void MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, + EALSMantleType MantleType); virtual bool MantleCheck(const FALSMantleTraceSettings& TraceSettings, EDrawDebugTrace::Type DebugType = EDrawDebugTrace::Type::ForOneFrame); @@ -626,7 +632,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter bool bBreakfallOnLand = true; /** If player hits to the ground with an amount of velocity greater than specified value, switch to breakfall state */ - UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Breakfall System", meta = (EditCondition = "bBreakfallOnLand")) + UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Breakfall System", meta = (EditCondition = + "bBreakfallOnLand")) float BreakfallOnLandVelocity = 600.0f; /** Ragdoll System */ @@ -636,7 +643,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter bool bRagdollOnLand = false; /** If player hits to the ground with an amount of velocity greater than specified value, switch to ragdoll state */ - UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Ragdoll System", meta = (EditCondition = "bRagdollOnLand")) + UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Ragdoll System", meta = (EditCondition = + "bRagdollOnLand")) float RagdollOnLandVelocity = 1000.0f; UPROPERTY(BlueprintReadOnly, Category = "ALS|Ragdoll System") diff --git a/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h b/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h index a9b38c41..353ba760 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h @@ -176,7 +176,8 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance AALSBaseCharacter* Character = nullptr; /** Character Information */ - UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information", Meta = ( + ShowOnlyInnerProperties)) FALSAnimCharacterInformation CharacterInformation; public: UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information") @@ -198,7 +199,8 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FALSOverlayState OverlayState = EALSOverlayState::Default; protected: /** Anim Graph - Grounded */ - UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded", Meta = ( + ShowOnlyInnerProperties)) FALSAnimGraphGrounded Grounded; public: UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded") @@ -217,7 +219,8 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FALSMovementDirection MovementDirection = EALSMovementDirection::Forward; protected: /** Anim Graph - In Air */ - UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - In Air", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - In Air", Meta = ( + ShowOnlyInnerProperties)) FALSAnimGraphInAir InAir; /** Anim Graph - Aiming Values */ @@ -238,19 +241,23 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FALSAnimGraphLayerBlending LayerBlendingValues; /** Anim Graph - Foot IK */ - UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Foot IK", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Foot IK", Meta = ( + ShowOnlyInnerProperties)) FALSAnimGraphFootIK FootIKValues; /** Turn In Place */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Turn In Place", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Turn In Place", Meta = ( + ShowOnlyInnerProperties)) FALSAnimTurnInPlace TurnInPlaceValues; /** Rotate In Place */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Rotate In Place", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Rotate In Place", Meta = ( + ShowOnlyInnerProperties)) FALSAnimRotateInPlace RotateInPlace; /** Configuration */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Main Configuration", Meta = (ShowOnlyInnerProperties)) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Main Configuration", Meta = ( + ShowOnlyInnerProperties)) FALSAnimConfiguration Config; /** Blend Curves */ @@ -293,5 +300,4 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FTimerHandle OnJumpedTimer; bool bCanPlayDynamicTransition = true; - }; diff --git a/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h index b043b3e2..ce170fff 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h @@ -57,6 +57,7 @@ class ALSV4_CPP_API UALSMathLibrary : public UBlueprintFunctionLibrary static bool AngleInRange(float Angle, float MinAngle, float MaxAngle, float Buffer, bool IncreaseBuffer); UFUNCTION(BlueprintCallable) - static EALSMovementDirection CalculateQuadrant(EALSMovementDirection Current, float FRThreshold, float FLThreshold, float BRThreshold, + static EALSMovementDirection CalculateQuadrant(EALSMovementDirection Current, float FRThreshold, float FLThreshold, + float BRThreshold, float BLThreshold, float Buffer, float Angle); }; From 8263750d90a0e53a695318b3492b7d6af95d4d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Wed, 2 Dec 2020 00:44:18 +0300 Subject: [PATCH 5/9] Code quality improvements --- .../Private/Character/AI/ALSAIController.cpp | 5 ++- .../Private/Character/ALSBaseCharacter.cpp | 10 ++--- .../Private/Character/ALSCharacter.cpp | 2 +- .../Animation/ALSCharacterAnimInstance.cpp | 2 +- .../Public/Character/ALSBaseCharacter.h | 37 ++++++++++--------- .../Public/Character/ALSPlayerController.h | 1 + .../Animation/ALSCharacterAnimInstance.h | 28 +++++++------- .../Animation/ALSPlayerCameraBehavior.h | 2 +- .../Notify/ALSAnimNotifyCameraShake.h | 2 +- .../Animation/Notify/ALSAnimNotifyFootstep.h | 4 +- .../Notify/ALSAnimNotifyGroundedEntryState.h | 4 +- .../Notify/ALSNotifyStateEarlyBlendOut.h | 4 +- .../Notify/ALSNotifyStateMovementAction.h | 2 +- .../Notify/ALSNotifyStateOverlayOverride.h | 2 +- .../Library/ALSCharacterStructLibrary.h | 2 +- 15 files changed, 56 insertions(+), 51 deletions(-) diff --git a/Source/ALSV4_CPP/Private/Character/AI/ALSAIController.cpp b/Source/ALSV4_CPP/Private/Character/AI/ALSAIController.cpp index 005796b1..f4f46c40 100644 --- a/Source/ALSV4_CPP/Private/Character/AI/ALSAIController.cpp +++ b/Source/ALSV4_CPP/Private/Character/AI/ALSAIController.cpp @@ -13,7 +13,10 @@ AALSAIController::AALSAIController() static ConstructorHelpers::FObjectFinder BehaviourDefault( TEXT("/ALSV4_CPP/AdvancedLocomotionV4/Blueprints/CharacterLogic/AI/ALS_BT_AICharacter")); - Behaviour = BehaviourDefault.Object; + if (BehaviourDefault.Succeeded()) + { + Behaviour = BehaviourDefault.Object; + } } void AALSAIController::OnPossess(APawn* InPawn) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index ac57b134..d6aef285 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -708,7 +708,7 @@ void AALSBaseCharacter::SetAcceleration(const FVector& NewAcceleration) void AALSBaseCharacter::RagdollUpdate(float DeltaTime) { // Set the Last Ragdoll Velocity. - FVector NewRagdollVel = GetMesh()->GetPhysicsLinearVelocity(FName(TEXT("root"))); + const FVector NewRagdollVel = GetMesh()->GetPhysicsLinearVelocity(FName(TEXT("root"))); LastRagdollVelocity = (NewRagdollVel != FVector::ZeroVector || IsLocallyControlled()) ? NewRagdollVel : LastRagdollVelocity / 2; @@ -1018,7 +1018,7 @@ void AALSBaseCharacter::UpdateDynamicMovementSettingsStandalone(EALSGait Allowed { // Get the Current Movement Settings. CurrentMovementSettings = GetTargetMovementSettings(); - float NewMaxSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait); + const float NewMaxSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait); // Update the Acceleration, Deceleration, and Ground Friction using the Movement Curve. // This allows for fine control over movement behavior at each speed (May not be suitable for replication). @@ -1036,7 +1036,7 @@ void AALSBaseCharacter::UpdateDynamicMovementSettingsNetworked(EALSGait AllowedG { // Get the Current Movement Settings. CurrentMovementSettings = GetTargetMovementSettings(); - float NewMaxSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait); + const float NewMaxSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait); // Update the Character Max Walk Speed to the configured speeds based on the currently Allowed Gait. if (IsLocallyControlled() || HasAuthority()) @@ -1489,8 +1489,8 @@ void AALSBaseCharacter::GetControlForwardRightVector(FVector& Forward, FVector& FVector AALSBaseCharacter::GetPlayerMovementInput() const { - FVector Forward; - FVector Right; + FVector Forward = FVector::ZeroVector; + FVector Right = FVector::ZeroVector; GetControlForwardRightVector(Forward, Right); return (Forward + Right).GetSafeNormal(); } diff --git a/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp index b8182222..9c170f35 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp @@ -79,7 +79,7 @@ void AALSCharacter::RagdollEnd() ECollisionChannel AALSCharacter::GetThirdPersonTraceParams(FVector& TraceOrigin, float& TraceRadius) { - FName CameraSocketName = bRightShoulder ? TEXT("TP_CameraTrace_R") : TEXT("TP_CameraTrace_L"); + const FName CameraSocketName = bRightShoulder ? TEXT("TP_CameraTrace_R") : TEXT("TP_CameraTrace_L"); TraceOrigin = GetMesh()->GetSocketLocation(CameraSocketName); TraceRadius = 15.0f; return ECC_Camera; diff --git a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp index 1d6f7f32..9abb12f5 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp @@ -548,7 +548,7 @@ void UALSCharacterAnimInstance::UpdateMovementValues(float DeltaSeconds) VelocityBlend.L = FMath::FInterpTo(VelocityBlend.L, TargetBlend.L, DeltaSeconds, Config.VelocityBlendInterpSpeed); VelocityBlend.R = FMath::FInterpTo(VelocityBlend.R, TargetBlend.R, DeltaSeconds, Config.VelocityBlendInterpSpeed); - // Set the Diagnal Scale Amount. + // Set the Diagonal Scale Amount. Grounded.DiagonalScaleAmount = CalculateDiagonalScaleAmount(); // Set the Relative Acceleration Amount and Interp the Lean Amount. diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index 30423998..f91bf605 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -53,7 +53,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter virtual void PostInitializeComponents() override; - void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; + virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; /** Ragdoll System */ @@ -357,13 +357,13 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter virtual void OnOverlayStateChanged(EALSOverlayState PreviousState); - void OnStartCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) override; + virtual void OnStartCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) override; - void OnEndCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) override; + virtual void OnEndCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) override; - void OnJumped_Implementation() override; + virtual void OnJumped_Implementation() override; - void Landed(const FHitResult& Hit) override; + virtual void Landed(const FHitResult& Hit) override; void OnLandFrictionReset(); @@ -455,6 +455,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter protected: /* Custom movement component*/ + UPROPERTY() UALSCharacterMovementComponent* MyCharacterMovementComponent; /** Input */ @@ -535,7 +536,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Essential Information */ UPROPERTY(BlueprintReadOnly, Category = "ALS|Essential Information") - FVector Acceleration; + FVector Acceleration = FVector::ZeroVector; UPROPERTY(BlueprintReadOnly, Category = "ALS|Essential Information") bool bIsMoving = false; @@ -561,13 +562,13 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Replicated Essential Information*/ UPROPERTY(BlueprintReadOnly, Category = "ALS|Essential Information") - float EasedMaxAcceleration; + float EasedMaxAcceleration = 0.0f; UPROPERTY(BlueprintReadOnly, Replicated, Category = "ALS|Essential Information") - FVector ReplicatedCurrentAcceleration; + FVector ReplicatedCurrentAcceleration = FVector::ZeroVector; UPROPERTY(BlueprintReadOnly, Replicated, Category = "ALS|Essential Information") - FRotator ReplicatedControlRotation; + FRotator ReplicatedControlRotation = FRotator::ZeroRotator; /** State Values */ @@ -600,10 +601,10 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Rotation System */ UPROPERTY(BlueprintReadOnly, Category = "ALS|Rotation System") - FRotator TargetRotation; + FRotator TargetRotation = FRotator::ZeroRotator; UPROPERTY(BlueprintReadOnly, Category = "ALS|Rotation System") - FRotator InAirRotation; + FRotator InAirRotation = FRotator::ZeroRotator; UPROPERTY(BlueprintReadOnly, Category = "ALS|Rotation System") float YawOffset = 0.0f; @@ -617,13 +618,13 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter FALSComponentAndTransform MantleLedgeLS; UPROPERTY(BlueprintReadOnly, Category = "ALS|Mantle System") - FTransform MantleTarget; + FTransform MantleTarget = FTransform::Identity; UPROPERTY(BlueprintReadOnly, Category = "ALS|Mantle System") - FTransform MantleActualStartOffset; + FTransform MantleActualStartOffset = FTransform::Identity; UPROPERTY(BlueprintReadOnly, Category = "ALS|Mantle System") - FTransform MantleAnimatedStartOffset; + FTransform MantleAnimatedStartOffset = FTransform::Identity; /** Breakfall System */ @@ -654,10 +655,10 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter bool bRagdollFaceUp = false; UPROPERTY(BlueprintReadOnly, Category = "ALS|Ragdoll System") - FVector LastRagdollVelocity; + FVector LastRagdollVelocity = FVector::ZeroVector; UPROPERTY(BlueprintReadOnly, Replicated, Category = "ALS|Ragdoll System") - FVector TargetRagdollLocation; + FVector TargetRagdollLocation = FVector::ZeroVector; /* Server ragdoll pull force storage*/ float ServerRagdollPull = 0.0f; @@ -667,7 +668,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Cached Variables */ - FVector PreviousVelocity; + FVector PreviousVelocity = FVector::ZeroVector; float PreviousAimYaw = 0.0f; @@ -687,7 +688,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter FTimerHandle OnLandedFrictionResetTimer; /* Smooth out aiming by interping control rotation*/ - FRotator AimingRotation; + FRotator AimingRotation = FRotator::ZeroRotator; /** We won't use curve based movement on networked games */ bool bDisableCurvedMovement = false; diff --git a/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h b/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h index 2ebda59a..16dd279b 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h +++ b/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h @@ -27,5 +27,6 @@ class ALSV4_CPP_API AALSPlayerController : public APlayerController private: /** Main character reference */ + UPROPERTY() AALSBaseCharacter* PossessedCharacter = nullptr; }; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h b/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h index 353ba760..05d69953 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h @@ -29,9 +29,9 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance GENERATED_BODY() public: - void NativeInitializeAnimation() override; + virtual void NativeInitializeAnimation() override; - void NativeUpdateAnimation(float DeltaSeconds) override; + virtual void NativeUpdateAnimation(float DeltaSeconds) override; UFUNCTION(BlueprintCallable) void PlayTransition(const FALSDynamicMontageParams& Parameters); @@ -210,7 +210,7 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FALSLeanAmount LeanAmount; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded") - FVector RelativeAccelerationAmount; + FVector RelativeAccelerationAmount = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded") FALSGroundedEntryState GroundedEntryState = EALSGroundedEntryState::None; @@ -229,7 +229,7 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FALSAnimGraphAimingValues AimingValues; public: UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Aiming Values") - FVector2D SmoothedAimingAngle; + FVector2D SmoothedAimingAngle = FVector2D::ZeroVector; protected: /** Anim Graph - Ragdoll */ UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Ragdoll") @@ -263,34 +263,34 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance /** Blend Curves */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* DiagonalScaleAmountCurve; + UCurveFloat* DiagonalScaleAmountCurve = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* StrideBlend_N_Walk; + UCurveFloat* StrideBlend_N_Walk = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* StrideBlend_N_Run; + UCurveFloat* StrideBlend_N_Run = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* StrideBlend_C_Walk; + UCurveFloat* StrideBlend_C_Walk = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* LandPredictionCurve; + UCurveFloat* LandPredictionCurve = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* LeanInAirCurve; + UCurveFloat* LeanInAirCurve = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveVector* YawOffset_FB; + UCurveVector* YawOffset_FB = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveVector* YawOffset_LR; + UCurveVector* YawOffset_LR = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Dynamic Transition") - UAnimSequenceBase* TransitionAnim_R; + UAnimSequenceBase* TransitionAnim_R = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Dynamic Transition") - UAnimSequenceBase* TransitionAnim_L; + UAnimSequenceBase* TransitionAnim_L = nullptr; private: FTimerHandle OnPivotTimer; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h b/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h index f23e1e48..a223cdb1 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h @@ -33,7 +33,7 @@ class ALSV4_CPP_API UALSPlayerCameraBehavior : public UAnimInstance APlayerController* PlayerController = nullptr; protected: - void NativeUpdateAnimation(float DeltaSeconds) override; + virtual void NativeUpdateAnimation(float DeltaSeconds) override; protected: UPROPERTY(VisibleAnywhere, BlueprintReadOnly) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h index 9b7f827e..47b6cea1 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h @@ -21,7 +21,7 @@ class ALSV4_CPP_API UALSAnimNotifyCameraShake : public UAnimNotify { GENERATED_BODY() - void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h index ef806c2c..71881426 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h @@ -23,9 +23,9 @@ class ALSV4_CPP_API UALSAnimNotifyFootstep : public UAnimNotify { GENERATED_BODY() - void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; - FString GetNotifyName_Implementation() const override; + virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h index 95445ab6..8d72fbaa 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h @@ -22,9 +22,9 @@ class ALSV4_CPP_API UALSAnimNotifyGroundedEntryState : public UAnimNotify { GENERATED_BODY() - void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; - FString GetNotifyName_Implementation() const override; + virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h index 58623eba..250eec81 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h @@ -22,9 +22,9 @@ class ALSV4_CPP_API UALSNotifyStateEarlyBlendOut : public UAnimNotifyState { GENERATED_BODY() - void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime) override; + virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime) override; - FString GetNotifyName_Implementation() const override; + virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h index 0be92135..ecb3f1c1 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h @@ -26,7 +26,7 @@ class ALSV4_CPP_API UALSNotifyStateMovementAction : public UAnimNotifyState virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; - FString GetNotifyName_Implementation() const override; + virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h index 3c3060bf..bdaf7165 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h @@ -24,7 +24,7 @@ class ALSV4_CPP_API UALSNotifyStateOverlayOverride : public UAnimNotifyState virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; - FString GetNotifyName_Implementation() const override; + virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h index a51f7908..757a32ef 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h @@ -180,7 +180,7 @@ struct FALSMovementSettings UPROPERTY(EditAnywhere) UCurveFloat* RotationRateCurve = nullptr; - float GetSpeedForGait(EALSGait Gait) + float GetSpeedForGait(EALSGait Gait) const { switch (Gait) { From 97ca23a6c7305153108d18bb96cd2d8443a95174 Mon Sep 17 00:00:00 2001 From: Sebastien <34646501+seb-exiin@users.noreply.github.com> Date: Tue, 1 Dec 2020 22:53:38 +0100 Subject: [PATCH 6/9] Prevent Character to climb on object with high velocity (#85) --- .../Private/Character/ALSBaseCharacter.cpp | 26 +++++++++++++++++++ .../Public/Character/ALSBaseCharacter.h | 5 ++++ 2 files changed, 31 insertions(+) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index d6aef285..21ea9cef 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -564,6 +564,14 @@ void AALSBaseCharacter::SetMovementModel() MovementData = *OutRow; } +bool AALSBaseCharacter::IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity) +{ + FVector PrimitiveComponentVelocity = PrimitiveComponent->GetComponentVelocity(); + + return (PrimitiveComponentVelocity.Size() < MaxVelocity); +} + + void AALSBaseCharacter::SetHasMovementInput(bool bNewHasMovementInput) { bHasMovementInput = bNewHasMovementInput; @@ -1231,7 +1239,18 @@ bool AALSBaseCharacter::MantleCheck(const FALSMantleTraceSettings& TraceSettings // Not a valid surface to mantle return false; } + + if (HitResult.GetComponent() != nullptr) + { + UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent(); + if (!IsComponentVelocityValid(PrimitiveComponent, AcceptableVelocityWhileMantling)) + { + //The surface to mantle moves too fast + return false; + } + } + const FVector InitialTraceImpactPoint = HitResult.ImpactPoint; const FVector InitialTraceNormal = HitResult.ImpactNormal; @@ -1302,6 +1321,13 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn) { // Step 1: Continually update the mantle target from the stored local transform to follow along with moving objects MantleTarget = UALSMathLibrary::MantleComponentLocalToWorld(MantleLedgeLS); + + if (MantleLedgeLS.Component != nullptr && !IsComponentVelocityValid(MantleLedgeLS.Component, AcceptableVelocityWhileMantling)) + { + //The surface to mantle moves too fast + MantleEnd(); + return; + } // Step 2: Update the Position and Correction Alphas using the Position/Correction curve set for each Mantle. const FVector CurveVec = MantleParams.PositionCorrectionCurve diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index f91bf605..be6e7964 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -405,6 +405,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter void SetMovementModel(); + bool IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity); + /** Input */ void PlayerForwardMovementInput(float Value); @@ -528,6 +530,9 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") UCurveFloat* MantleTimelineCurve; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") + float AcceptableVelocityWhileMantling = 10.0f; + /** Components */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Components") From 48c7390cbdbaf03f47c97e8c507400882e741e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Wed, 2 Dec 2020 00:56:36 +0300 Subject: [PATCH 7/9] Pushing required changes for more stable mantle velocity check --- .../Private/Character/ALSBaseCharacter.cpp | 20 ++----------------- .../Public/Character/ALSBaseCharacter.h | 3 +-- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index 21ea9cef..cdbed44c 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -564,14 +564,6 @@ void AALSBaseCharacter::SetMovementModel() MovementData = *OutRow; } -bool AALSBaseCharacter::IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity) -{ - FVector PrimitiveComponentVelocity = PrimitiveComponent->GetComponentVelocity(); - - return (PrimitiveComponentVelocity.Size() < MaxVelocity); -} - - void AALSBaseCharacter::SetHasMovementInput(bool bNewHasMovementInput) { bHasMovementInput = bNewHasMovementInput; @@ -1243,10 +1235,9 @@ bool AALSBaseCharacter::MantleCheck(const FALSMantleTraceSettings& TraceSettings if (HitResult.GetComponent() != nullptr) { UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent(); - - if (!IsComponentVelocityValid(PrimitiveComponent, AcceptableVelocityWhileMantling)) + if (PrimitiveComponent && PrimitiveComponent->GetComponentVelocity().Size() > AcceptableVelocityWhileMantling) { - //The surface to mantle moves too fast + // The surface to mantle moves too fast return false; } } @@ -1321,13 +1312,6 @@ void AALSBaseCharacter::MantleUpdate(float BlendIn) { // Step 1: Continually update the mantle target from the stored local transform to follow along with moving objects MantleTarget = UALSMathLibrary::MantleComponentLocalToWorld(MantleLedgeLS); - - if (MantleLedgeLS.Component != nullptr && !IsComponentVelocityValid(MantleLedgeLS.Component, AcceptableVelocityWhileMantling)) - { - //The surface to mantle moves too fast - MantleEnd(); - return; - } // Step 2: Update the Position and Correction Alphas using the Position/Correction curve set for each Mantle. const FVector CurveVec = MantleParams.PositionCorrectionCurve diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index be6e7964..23179dbc 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -405,8 +405,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter void SetMovementModel(); - bool IsComponentVelocityValid(UPrimitiveComponent* PrimitiveComponent, float MaxVelocity); - /** Input */ void PlayerForwardMovementInput(float Value); @@ -530,6 +528,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") UCurveFloat* MantleTimelineCurve; + /** If a dynamic object has a velocity bigger than value, do not start mantle */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") float AcceptableVelocityWhileMantling = 10.0f; From ea93043ec8a6716776b8ce61daa0e07aecdf59e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Wed, 2 Dec 2020 00:59:16 +0300 Subject: [PATCH 8/9] Fix a typo in the comment --- Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index 23179dbc..d087a759 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -528,7 +528,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") UCurveFloat* MantleTimelineCurve; - /** If a dynamic object has a velocity bigger than value, do not start mantle */ + /** If a dynamic object has a velocity bigger than this value, do not start mantle */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") float AcceptableVelocityWhileMantling = 10.0f; From 545aa3b1330133af023487d09d06578d36a408bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Can=20Yan=C4=B1ko=C4=9Flu?= Date: Wed, 2 Dec 2020 01:00:17 +0300 Subject: [PATCH 9/9] Update version to 4.11 --- ALSV4_CPP.uplugin | 2 +- .../Blueprints/UI/ALS_HUD.uasset | Bin 573141 -> 573141 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/ALSV4_CPP.uplugin b/ALSV4_CPP.uplugin index 41e01911..ba7604ab 100644 --- a/ALSV4_CPP.uplugin +++ b/ALSV4_CPP.uplugin @@ -1,7 +1,7 @@ { "FileVersion": 3, "Version": 1, - "VersionName": "4.10", + "VersionName": "4.11", "FriendlyName": "Advanced Locomotion System V4 on C++", "Description": "Performance optimized C++ port of LongmireLocomotion's Advanced Locomotion System V4", "Category": "Animation", diff --git a/Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset b/Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset index 8d1346559705229d54df6d291c66ad2245b0f284..baed6000c389439b662eb13ef9016bcd51870f29 100644 GIT binary patch delta 1610 zcmZWpJ&2uE5apTozNA!1K#`DVND)Wtsal6Z$IcLr}t5^YxemXdo&5ZPexsJa z6)XjkCGU%rrXNj!N~Pg&^PAn>qyEmvy2DcR>djrrB&#KtxZ00$1nRq#7G#3(e1QwmqRZ8LDS%8EZ*M zNsQ<0qj;a36qWKS&I6PF(Sr(c&$BZKzy`$xJ2Li`Ap6DwHMTTGS(EL&A;|G9)vf ze*Q(B9*9$s7O|0Y+)|3kL?_181OfaoI^G?a^w0Gw(c1o(U!EZdH3`rxLd#^EaguG} zSUp5%l>Z!|e^n)ljv|^?QJhzi0ycrH5|Id^1AkSb^WD_=45B=-s_Bf>6b(lgORbrj zi7=acel*Rj-e3b*qOmQKPbR4o&}PftX1O|2ulwNc_0`{hXSRCtv4Xk*5!7b}Z9u4; zk_FQBVwkVK^7!Vh{ohBrUH#MVb+=DF*Oq+nm`T8>>6)#;x@v@2Im7=D*ZlO%i5a3v zoUDcbs}TpzWuGym)J*jv;@3#2Z*M%UVqtDx83hc!8Z{7zx2kn5C94UbZNT~TOt(Cm zB1x;>AtrTt04r+H$PxobCKuP8bnz1%?xQIpkNzqD3deI<`+88F28VUB;L5LtT!v(|`rV4C<~)Gt-EHxw(2{SU?Y&k~%Rc0S0jAg}XYx^PJ~-=FH`dXD)9% zeCe87p1P}^zimH%eB{1cfBE$KU;Arcn@o> zZB33bQYNmh7N2ZNIZ9?5*bYy>J9+rJsc)`9X2C)v1WBUJRriP(Ed?pV@24g|y*F)E z8k>p;F-CA8Kxi-%RudCPKiqt@yMNT*^LV#!YGZDRYDNGfwI$b#3n>}F7)y?}|Kr7O z-LUPIZtJAqxu@IEUpUnH;mN(79ZhqL-p3rUu+hx|RSJnBSs>-Fa@OxxPAXWdwSq2{ z>cr0^v{)zylawf{oL!Utu|0}-@VOZR$Xd#=q9>-1rIbXi71O9P7qcSew*!j6P#8oA zEym<+bj6Xw;=udHQNk+X@MPHZyiQ+8$e~mNm>L(K8#)fArliMr5@?tn?H(BQ%P;8g z5UjBt9X1=29v_o$rA5do2v_S@hp+5^>808J!jVg>33Y9&m#Vo111SZo_EB?lEBcoe zAq>HWAQ++-N7kF{Ln=iAQ}bk25zF0F90oQ;^TuSX5XC0VC(71hc3ft2mq*ja4#inO zr?W(I%o+(zg0w1?3ayS*cOTiT?p`_lJ8#WaH?CrUT2wP}b5XAY$T>O8KHFyIt1msV zW?lc+fo@a(%-h}F(-Jsl6BwDgm5VquZ!C?okIjJaem zDWnJnngzHbN^^VTiEiHlL6zuLOkvfgQaltjn?Vbtz6>Ay(2YmKov(H~#vh&R4vwbI ztArE`8m*01M#F)gW1!;oFXLR!g%8z_g3^xh7(da`qnbE*iwctoFpbM>*=&?2|C((!xGs_of`zMiDdhnQ5s zHZsMsrrx`z%I3D8`@Z{bvQTPc&{vOBG1fVwWt9>&P(e#Te)#sBR%D@ItC(!SmYXs) y93Zu53_}T_;gSYPr>@z)dt~~&W$n-Xjvv=->o1-kPx|+Fu01#$-@f+ty?+C*sJzMm