Skip to content

Commit

Permalink
Merge pull request #92 from dyanikoglu/dev
Browse files Browse the repository at this point in the history
Release v4.11
  • Loading branch information
dyanikoglu committed Dec 1, 2020
2 parents a352350 + 545aa3b commit c35458a
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 125 deletions.
2 changes: 1 addition & 1 deletion ALSV4_CPP.uplugin
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Binary file modified Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset
Binary file not shown.
5 changes: 4 additions & 1 deletion Source/ALSV4_CPP/Private/Character/AI/ALSAIController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ AALSAIController::AALSAIController()
static ConstructorHelpers::FObjectFinder<UBehaviorTree> 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)
Expand Down
97 changes: 67 additions & 30 deletions Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -257,8 +258,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,
Expand All @@ -276,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);
}
Expand Down Expand Up @@ -339,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();
}

Expand Down Expand Up @@ -461,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);
}
}

Expand All @@ -481,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.
Expand All @@ -501,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)
{
Expand Down Expand Up @@ -538,13 +548,15 @@ 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.
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();
Expand Down Expand Up @@ -597,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);
}
Expand Down Expand Up @@ -648,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"))));
}
Expand All @@ -672,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
Expand All @@ -688,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);
}

Expand All @@ -709,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);
Expand All @@ -719,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;
Expand All @@ -737,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;
Expand Down
6 changes: 4 additions & 2 deletions Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit c35458a

Please sign in to comment.