From 29fd695a0367f5701ceef0e3f71f66a05d086376 Mon Sep 17 00:00:00 2001 From: Maxime Date: Wed, 22 Nov 2023 22:59:30 +0100 Subject: [PATCH] Fix air spline locomotion and flat spline --- Pawn_Unreal/Content/Characters/BP_Judy.uasset | 4 +- .../Characters/Base/ABP_Character.uasset | 4 +- .../Combat/BP_CombatPlatformerPath.uasset | 4 +- .../1/XM/TP8DFTZ6ODOTSDOLG6WEXZ.uasset | 3 ++ .../9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset | 4 +- .../A/1J/FGN60CK2BMBEJRXHZ72TKV.uasset | 4 +- .../B/0Z/X5N2DTGOJMHQWHOBBKFNDX.uasset | 2 +- .../PwnCharacterMovementComponent.cpp | 38 ++++++++++++------- .../Combat/PwnCombatPlatformerPath.cpp | 20 ++++++++++ .../PwnCharacterMovementComponent.h | 2 +- 10 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/1/XM/TP8DFTZ6ODOTSDOLG6WEXZ.uasset diff --git a/Pawn_Unreal/Content/Characters/BP_Judy.uasset b/Pawn_Unreal/Content/Characters/BP_Judy.uasset index ee4a245..4996945 100644 --- a/Pawn_Unreal/Content/Characters/BP_Judy.uasset +++ b/Pawn_Unreal/Content/Characters/BP_Judy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9832d56e18c422c2adc83644df67cfbfd9aadf2321286c45356ee8e6bf2f4bb3 -size 226968 +oid sha256:ed88d1f35ee0aa183b51937ec2ade13438c2ab0d9926700a57b02bd56728c2ad +size 239658 diff --git a/Pawn_Unreal/Content/Characters/Base/ABP_Character.uasset b/Pawn_Unreal/Content/Characters/Base/ABP_Character.uasset index 7865e99..16c9bb6 100644 --- a/Pawn_Unreal/Content/Characters/Base/ABP_Character.uasset +++ b/Pawn_Unreal/Content/Characters/Base/ABP_Character.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94bbc78f7257a580831f357149d4572a7e5c492a494331c293fb6eaf7e54f308 -size 212741 +oid sha256:37d274037d56a9079276ff4770dfae1e8130dd82ff055c84dab5e3352b7cb899 +size 266285 diff --git a/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset b/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset index ccfd72e..0d93d4c 100644 --- a/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset +++ b/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:13f12984b42554e54f741cd53e6492d56519d31e43f5029c784c57ecbf215f57 -size 99027 +oid sha256:f56c72aa6ef2cf4c46483b763b107c70ed8bad7119a90bb4232a881e07490ebb +size 129674 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/1/XM/TP8DFTZ6ODOTSDOLG6WEXZ.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/1/XM/TP8DFTZ6ODOTSDOLG6WEXZ.uasset new file mode 100644 index 0000000..5ee54d9 --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/1/XM/TP8DFTZ6ODOTSDOLG6WEXZ.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:89d226422dbea5d390f2a6802a4ae8f1a7208719358bf16b4f7b99aedf65096d +size 4468 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset index d7fcec2..c5d517e 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a21106cbd0ee258deaa6f407c978e30c15b7da120d8c4f4101592425534f7871 -size 110263 +oid sha256:2414dd3fc45a395d203ef3c5abc68322f5dcafd52f3e0f11daf4a5a62c2302cf +size 284413 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/1J/FGN60CK2BMBEJRXHZ72TKV.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/1J/FGN60CK2BMBEJRXHZ72TKV.uasset index 8fb96ea..6b98691 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/1J/FGN60CK2BMBEJRXHZ72TKV.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/1J/FGN60CK2BMBEJRXHZ72TKV.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:82535bbab66a929d36bcc325456ac3efb5ac6650d0410c4e083719f8f7af21ca -size 6436 +oid sha256:74c3d9cbdd7b3dffcdf8c839ac50d82da1cefd9edd442ed17c41e3db3fa515b5 +size 6595 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/0Z/X5N2DTGOJMHQWHOBBKFNDX.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/0Z/X5N2DTGOJMHQWHOBBKFNDX.uasset index 957dd1c..9578655 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/0Z/X5N2DTGOJMHQWHOBBKFNDX.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/0Z/X5N2DTGOJMHQWHOBBKFNDX.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f13050ce50d67fa4833b05b66e7e91740d2dfeced5edf69dae8bfa3042a3e317 +oid sha256:314ef25ab8e4a9d7fbfad3f559cccee22f93f63bee9e4cd7e79ba0b6b60f5479 size 4468 diff --git a/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp b/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp index 318dc25..641a436 100644 --- a/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp @@ -48,8 +48,7 @@ void UPwnCharacterMovementComponent::OnMovementModeChanged(EMovementMode Previou Super::OnMovementModeChanged(PreviousMovementMode, PreviousCustomMode); // React to changes in the movement mode. - if (MovementMode == MOVE_Custom && CustomMovementMode == SplineWalking) - { + if (MovementMode == MOVE_Custom && CustomMovementMode == SplineWalking) { // make sure we update our new floor/base on initial entry of the walking physics FindFloor(UpdatedComponent->GetComponentLocation(), CurrentFloor, false); AdjustFloorHeight(); @@ -112,7 +111,7 @@ bool UPwnCharacterMovementComponent::IsCustomMovementMode(const ECustomMovementM void UPwnCharacterMovementComponent::RecomputeTangentAndAcceleration() { Tangent2D = CombatPath->Spline->GetTangentAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World).GetSafeNormal2D(); // Recalculate acceleration so the input is relative to the spline - Acceleration = Tangent2D * Acceleration.Size2D() * FMath::Sign(Acceleration.X); + Acceleration = Tangent2D * Acceleration.Size2D() * FMath::Sign(Acceleration.X) * DotDirection; } void UPwnCharacterMovementComponent::UpdatePawnVelocity(const float TimeTick) { @@ -140,10 +139,23 @@ void UPwnCharacterMovementComponent::UpdatePawnVelocity(const float TimeTick) { DistanceAlongSpline = NewDistanceAlongSpline; } -void UPwnCharacterMovementComponent::UpdateDistanceAlongSpline() { +void UPwnCharacterMovementComponent::UpdateDistanceAlongSplineAndLocation() { // Maintain coherent distance along spline with location - const float InputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(UpdatedComponent->GetComponentLocation()); - DistanceAlongSpline = CombatPath->Spline->GetDistanceAlongSplineAtSplineInputKey(InputKey); + FHitResult Hit; + FCollisionQueryParams QueryParams; + QueryParams.AddIgnoredActor(GetOwner()); + if (GetWorld()->LineTraceSingleByChannel(Hit, UpdatedComponent->GetComponentLocation(), + UpdatedComponent->GetComponentLocation() + FVector(0.0f, 0.0f, -10000.0f), + ECC_Visibility, QueryParams)) { + + FVector ImpactPoint = Hit.ImpactPoint; + const float InputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(ImpactPoint); + DistanceAlongSpline = CombatPath->Spline->GetDistanceAlongSplineAtSplineInputKey(InputKey); + } + + FVector TargetLocation = CombatPath->Spline->GetLocationAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World); + TargetLocation.Z = UpdatedComponent->GetComponentLocation().Z; + UpdatedComponent->SetWorldLocation(TargetLocation); } void UPwnCharacterMovementComponent::PhysSplineWalking(const float DeltaTime, int32 Iterations) { @@ -183,15 +195,15 @@ void UPwnCharacterMovementComponent::PhysSplineWalking(const float DeltaTime, in const FVector OldLocation = UpdatedComponent->GetComponentLocation(); const FFindFloorResult OldFloor = CurrentFloor; + RecomputeTangentAndAcceleration(); /* -- PAWN MODIFICATIONS -- */ + Acceleration.Z = 0.f; + RestorePreAdditiveRootMotionVelocity(); // Ensure velocity is horizontal. MaintainHorizontalGroundVelocity(); const FVector OldVelocity = Velocity; - RecomputeTangentAndAcceleration(); /* -- PAWN MODIFICATIONS -- */ - Acceleration.Z = 0.f; - // Apply acceleration if (!HasAnimRootMotion() && !CurrentRootMotion.HasOverrideVelocity()) { CalcVelocity(TimeTick, GroundFriction, false, GetMaxBrakingDeceleration()); @@ -343,7 +355,7 @@ void UPwnCharacterMovementComponent::PhysSplineWalking(const float DeltaTime, in MaintainHorizontalGroundVelocity(); } - UpdateDistanceAlongSpline(); /* -- PAWN MODIFICATIONS -- */ + UpdateDistanceAlongSplineAndLocation(); /* -- PAWN MODIFICATIONS -- */ } UE_DISABLE_OPTIMIZATION @@ -353,6 +365,8 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in return; } + RecomputeTangentAndAcceleration(); /* -- PAWN MODIFICATIONS -- */ + FVector FallAcceleration = GetFallingLateralAcceleration(DeltaTime); FallAcceleration.Z = 0.f; const bool bHasLimitedAirControl = ShouldLimitAirControl(DeltaTime, FallAcceleration); @@ -367,8 +381,6 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in const FQuat PawnRotation = UpdatedComponent->GetComponentQuat(); bJustTeleported = false; - RecomputeTangentAndAcceleration(); /* -- PAWN MODIFICATIONS -- */ - const FVector OldVelocityWithRootMotion = Velocity; RestorePreAdditiveRootMotionVelocity(); @@ -657,7 +669,7 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in } } - UpdateDistanceAlongSpline(); /* -- PAWN MODIFICATIONS -- */ + UpdateDistanceAlongSplineAndLocation(); /* -- PAWN MODIFICATIONS -- */ } UE_ENABLE_OPTIMIZATION diff --git a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp index 19a06e4..7612c61 100644 --- a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp @@ -19,6 +19,26 @@ void APwnCombatPlatformerPath::BeginPlay() { UPwnGameplayModeSubsystem* Subsystem = GetWorld()->GetSubsystem(); check(Subsystem); Subsystem->RegisterCombatPath(this); + + const FVector FirstPointLocation = Spline->GetLocationAtSplinePoint(0, ESplineCoordinateSpace::World); + float FirstPointZ = FirstPointLocation.Z; + + const int32 PointsCount = Spline->GetNumberOfSplinePoints(); + for (int i = 0; i < PointsCount; ++i) { + FVector NewLocation = Spline->GetLocationAtSplinePoint(i, ESplineCoordinateSpace::World); + NewLocation.Z = FirstPointZ; + Spline->SetLocationAtSplinePoint(i, NewLocation, ESplineCoordinateSpace::World, false); + + FVector ArriveTangent = Spline->GetArriveTangentAtSplinePoint(i, ESplineCoordinateSpace::World); + FVector LeaveTangent = Spline->GetLeaveTangentAtSplinePoint(i, ESplineCoordinateSpace::World); + + ArriveTangent.Z = 0; + LeaveTangent.Z = 0; + Spline->SetTangentsAtSplinePoint(i, ArriveTangent, LeaveTangent, ESplineCoordinateSpace::World, false); + } + + Spline->UpdateSpline(); + Super::BeginPlay(); } diff --git a/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h b/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h index 2df4ecf..2faff65 100644 --- a/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h +++ b/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h @@ -52,7 +52,7 @@ private: void UpdatePawnVelocity(const float TimeTick); - void UpdateDistanceAlongSpline(); + void UpdateDistanceAlongSplineAndLocation(); void PhysSplineWalking(const float DeltaTime, int32 Iterations);