From 028e228c8f109d33e825f7c7fe86b0dba8794bba Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 23 Nov 2023 00:06:48 +0100 Subject: [PATCH] Add Flatten Spline into Combat Platformer Path --- Pawn_Unreal/Content/Characters/BP_Judy.uasset | 4 +- .../Content/Core/GM_MainGameMode.uasset | 4 +- .../Input/BP_MainPlayerController.uasset | 4 +- .../Camera/BP_MainCameraManager.uasset | 4 +- .../Modes/BPC_GameplayModeNotifier.uasset | 3 -- .../Combat/BP_CombatPlatformerPath.uasset | 3 -- .../Systems/Modes/E_GameplayMode.uasset | 3 -- .../3/ZX/V7QFRP3DMWRT8NZCJQYVRB.uasset | 2 +- .../9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset | 4 +- .../C/6U/C2O2TW7RAVDUQGZS7QLKMX.uasset | 3 -- .../PwnCharacterMovementComponent.cpp | 39 +++++++++++-------- .../Combat/PwnCombatPlatformerPath.cpp | 14 +++++-- .../PwnGameplayModeSubsystem.cpp | 9 +---- .../Combat/PwnCombatPlatformerPath.h | 5 ++- .../GameplayModes/PwnGameplayModeSubsystem.h | 5 +-- .../Source/Pawn/Public/Utils/EngineUtils.h | 11 +++++- 16 files changed, 61 insertions(+), 56 deletions(-) delete mode 100644 Pawn_Unreal/Content/Systems/Modes/BPC_GameplayModeNotifier.uasset delete mode 100644 Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset delete mode 100644 Pawn_Unreal/Content/Systems/Modes/E_GameplayMode.uasset delete mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/C/6U/C2O2TW7RAVDUQGZS7QLKMX.uasset diff --git a/Pawn_Unreal/Content/Characters/BP_Judy.uasset b/Pawn_Unreal/Content/Characters/BP_Judy.uasset index 4996945..02f283d 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:ed88d1f35ee0aa183b51937ec2ade13438c2ab0d9926700a57b02bd56728c2ad -size 239658 +oid sha256:d6881e0fd1cf9f28c1d39877ffaac2336180b96da284f3fe3bb27e083b0fa36f +size 217961 diff --git a/Pawn_Unreal/Content/Core/GM_MainGameMode.uasset b/Pawn_Unreal/Content/Core/GM_MainGameMode.uasset index 6f27a80..1b362cf 100644 --- a/Pawn_Unreal/Content/Core/GM_MainGameMode.uasset +++ b/Pawn_Unreal/Content/Core/GM_MainGameMode.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f53385ee53e9a00d91eb9662865b5ba58667a6439a1349210b151b3feaba2872 -size 139971 +oid sha256:d985754c3ea10c751cdc69a0fbcbb68ae51a7298d8bb71235576b6c127079523 +size 13761 diff --git a/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset b/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset index db83481..3c9165b 100644 --- a/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset +++ b/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3dd40388fcf8b25c304a4abd4426a14b6cd29096ae5f1a7965974321c4de74cf -size 414085 +oid sha256:0a3d83a4007eb2b0e785528f71283f2fc8bc21fd41a3338d2a2a1118cf38516e +size 268121 diff --git a/Pawn_Unreal/Content/Systems/Camera/BP_MainCameraManager.uasset b/Pawn_Unreal/Content/Systems/Camera/BP_MainCameraManager.uasset index 55dd6cc..c435b3f 100644 --- a/Pawn_Unreal/Content/Systems/Camera/BP_MainCameraManager.uasset +++ b/Pawn_Unreal/Content/Systems/Camera/BP_MainCameraManager.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fcf4c4ca8525c9cbaaa7c7ecd899c2521454cfaf1d296ee1a0fab419a87aec37 -size 380020 +oid sha256:155a440d5b0eb481008779e3cbbdc57674746b453d91f0094b7066f2d04623da +size 382332 diff --git a/Pawn_Unreal/Content/Systems/Modes/BPC_GameplayModeNotifier.uasset b/Pawn_Unreal/Content/Systems/Modes/BPC_GameplayModeNotifier.uasset deleted file mode 100644 index 14cd37c..0000000 --- a/Pawn_Unreal/Content/Systems/Modes/BPC_GameplayModeNotifier.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d8dd0413aa31ef5316a87f935cfb9a868bbb33466d06422d7351bbfafca981f1 -size 57386 diff --git a/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset b/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset deleted file mode 100644 index 0d93d4c..0000000 --- a/Pawn_Unreal/Content/Systems/Modes/Combat/BP_CombatPlatformerPath.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f56c72aa6ef2cf4c46483b763b107c70ed8bad7119a90bb4232a881e07490ebb -size 129674 diff --git a/Pawn_Unreal/Content/Systems/Modes/E_GameplayMode.uasset b/Pawn_Unreal/Content/Systems/Modes/E_GameplayMode.uasset deleted file mode 100644 index b53db5c..0000000 --- a/Pawn_Unreal/Content/Systems/Modes/E_GameplayMode.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9dabc68b3eab183011a77fbd8023f6599472d1e5ef0e73b910291f39a018e92a -size 2334 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/ZX/V7QFRP3DMWRT8NZCJQYVRB.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/ZX/V7QFRP3DMWRT8NZCJQYVRB.uasset index 16d71aa..32af73e 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/ZX/V7QFRP3DMWRT8NZCJQYVRB.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/ZX/V7QFRP3DMWRT8NZCJQYVRB.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e77e28a7cb0d839eb28ac303f81b6a30d46f1c306155a6049708caba071ddf84 +oid sha256:2a302cfe5a1a23a60611f1def2d9827d0424778202e09fc91523b84a87779292 size 4354 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 c5d517e..ab67cb9 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:2414dd3fc45a395d203ef3c5abc68322f5dcafd52f3e0f11daf4a5a62c2302cf -size 284413 +oid sha256:b44d29873f5b9283e01f56ae5071217fd9a4dc983d8ce46a80e345769258dae2 +size 249503 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/C/6U/C2O2TW7RAVDUQGZS7QLKMX.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/C/6U/C2O2TW7RAVDUQGZS7QLKMX.uasset deleted file mode 100644 index 963de28..0000000 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/C/6U/C2O2TW7RAVDUQGZS7QLKMX.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:35cd85e45d0ac186e19f003dc3e200b6120ebd78cd4517e3effcc17c6ce37ee7 -size 4468 diff --git a/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp b/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp index 641a436..8243271 100644 --- a/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp @@ -1,6 +1,7 @@ #include "Characters/PwnCharacterMovementComponent.h" #include "Characters/PwnCharacterBase.h" +#include "Components/CapsuleComponent.h" #include "Components/SplineComponent.h" #include "GameplayModes/PwnGameplayModeSubsystem.h" #include "GameplayModes/Combat/PwnCombatPlatformerPath.h" @@ -86,16 +87,24 @@ void UPwnCharacterMovementComponent::EnterSplineFollowMode() { const UPwnGameplayModeSubsystem* Subsystem = GetWorld()->GetSubsystem(); check(Subsystem); - FVector OutLocation; + APwnCombatPlatformerPath* OutCombatPath; - float OutDistanceAloneSpline; - if (Subsystem->FindClosestCombatPathLocation(UpdatedComponent->GetComponentLocation(), OutLocation, OutCombatPath, OutDistanceAloneSpline)) { - DistanceAlongSpline = OutDistanceAloneSpline; + if (Subsystem->FindClosestCombatPathLocation(UpdatedComponent->GetComponentLocation(), OutCombatPath)) { CombatPath = OutCombatPath; DotDirection = CombatPath->Reversed ? -1.0f : 1.0f; - FVector TargetLocation = CombatPath->Spline->GetLocationAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World); - TargetLocation.Z = UpdatedComponent->GetComponentLocation().Z; - UpdatedComponent->SetWorldLocation(TargetLocation); + + float ClosestInputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(UpdatedComponent->GetComponentLocation()); + FVector ClosestLocation = CombatPath->Spline->GetLocationAtSplineInputKey(ClosestInputKey, ESplineCoordinateSpace::World); + + FHitResult Hit; + if (GetWorld()->LineTraceSingleByChannel(Hit, ClosestLocation, ClosestLocation + FVector(0.0f, 0.0f, -10000.0f), + ECC_Visibility, IGNORE_OWNER_PARAMS)) { + const float SplineKey = CombatPath->FlattenSpline->FindInputKeyClosestToWorldLocation(Hit.ImpactPoint); + DistanceAlongSpline = CombatPath->FlattenSpline->GetDistanceAlongSplineAtSplineInputKey(SplineKey); + + ClosestLocation.Z += CharacterOwner->GetCapsuleComponent()->GetScaledCapsuleHalfHeight(); + UpdatedComponent->SetWorldLocation(ClosestLocation); + } } } @@ -109,7 +118,7 @@ bool UPwnCharacterMovementComponent::IsCustomMovementMode(const ECustomMovementM } void UPwnCharacterMovementComponent::RecomputeTangentAndAcceleration() { - Tangent2D = CombatPath->Spline->GetTangentAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World).GetSafeNormal2D(); + Tangent2D = CombatPath->FlattenSpline->GetTangentAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World).GetSafeNormal2D(); // Recalculate acceleration so the input is relative to the spline Acceleration = Tangent2D * Acceleration.Size2D() * FMath::Sign(Acceleration.X) * DotDirection; } @@ -127,9 +136,9 @@ void UPwnCharacterMovementComponent::UpdatePawnVelocity(const float TimeTick) { VelocityDirection = FMath::Sign(VelocityDirection); // -1, 0 or 1 float NewDistanceAlongSpline = DistanceAlongSpline + VelocityDirection * VelocitySize2D * TimeTick; - NewDistanceAlongSpline = FMath::Clamp(NewDistanceAlongSpline, 0.0f, CombatPath->Spline->GetSplineLength()); + NewDistanceAlongSpline = FMath::Clamp(NewDistanceAlongSpline, 0.0f, CombatPath->FlattenSpline->GetSplineLength()); - FVector TargetLocation = CombatPath->Spline->GetLocationAtDistanceAlongSpline(NewDistanceAlongSpline, ESplineCoordinateSpace::World); + FVector TargetLocation = CombatPath->FlattenSpline->GetLocationAtDistanceAlongSpline(NewDistanceAlongSpline, ESplineCoordinateSpace::World); TargetLocation.Z = OldLocation.Z; const FVector Direction = (TargetLocation - OldLocation).GetSafeNormal2D(); @@ -142,18 +151,16 @@ void UPwnCharacterMovementComponent::UpdatePawnVelocity(const float TimeTick) { void UPwnCharacterMovementComponent::UpdateDistanceAlongSplineAndLocation() { // Maintain coherent distance along spline with location 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)) { + ECC_Visibility, IGNORE_OWNER_PARAMS)) { FVector ImpactPoint = Hit.ImpactPoint; - const float InputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(ImpactPoint); - DistanceAlongSpline = CombatPath->Spline->GetDistanceAlongSplineAtSplineInputKey(InputKey); + const float InputKey = CombatPath->FlattenSpline->FindInputKeyClosestToWorldLocation(ImpactPoint); + DistanceAlongSpline = CombatPath->FlattenSpline->GetDistanceAlongSplineAtSplineInputKey(InputKey); } - FVector TargetLocation = CombatPath->Spline->GetLocationAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World); + FVector TargetLocation = CombatPath->FlattenSpline->GetLocationAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World); TargetLocation.Z = UpdatedComponent->GetComponentLocation().Z; UpdatedComponent->SetWorldLocation(TargetLocation); } diff --git a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp index 7612c61..2c03d20 100644 --- a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp @@ -7,6 +7,7 @@ APwnCombatPlatformerPath::APwnCombatPlatformerPath() { PrimaryActorTick.bCanEverTick = false; Spline = CreateDefaultSubobject(TEXT("Spline")); + Spline->ReparamStepsPerSegment = 100.0f; SetRootComponent(Spline); #if WITH_EDITORONLY_DATA @@ -20,24 +21,29 @@ void APwnCombatPlatformerPath::BeginPlay() { check(Subsystem); Subsystem->RegisterCombatPath(this); + FlattenSpline = NewObject(this, TEXT("FlattenSpline")); + FlattenSpline->SetClosedLoop(Spline->IsClosedLoop(), false); + FlattenSpline->ReparamStepsPerSegment = Spline->ReparamStepsPerSegment; + FlattenSpline->ClearSplinePoints(false); + const FVector FirstPointLocation = Spline->GetLocationAtSplinePoint(0, ESplineCoordinateSpace::World); - float FirstPointZ = FirstPointLocation.Z; + const 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); + FlattenSpline->AddSplinePoint(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); + FlattenSpline->SetTangentsAtSplinePoint(i, ArriveTangent, LeaveTangent, ESplineCoordinateSpace::World, false); } - Spline->UpdateSpline(); + FlattenSpline->UpdateSpline(); Super::BeginPlay(); } diff --git a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp index bd771ad..bbf4c2a 100644 --- a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp @@ -41,11 +41,8 @@ void UPwnGameplayModeSubsystem::UnregisterCombatPath(APwnCombatPlatformerPath* C CombatPaths.Remove(CombatPath); } -bool UPwnGameplayModeSubsystem::FindClosestCombatPathLocation(const FVector& Location, FVector& OutCombatPathLocation, - APwnCombatPlatformerPath*& OutCombatPath, float& OutDistanceAlongSpline) const { +bool UPwnGameplayModeSubsystem::FindClosestCombatPathLocation(const FVector& Location, APwnCombatPlatformerPath*& OutCombatPath) const { float ShortestDistance = FLT_MAX; - float ClosestKey = 0.0f; - FVector ClosestLocation = FVector::ZeroVector; APwnCombatPlatformerPath* ClosestCombatPath = nullptr; bool Found = false; @@ -57,17 +54,13 @@ bool UPwnGameplayModeSubsystem::FindClosestCombatPathLocation(const FVector& Loc const float CurrentDistance = FVector::DistSquared(Location, CurrentLocation); if (CurrentDistance < ShortestDistance) { ShortestDistance = CurrentDistance; - ClosestKey = CurrentKey; - ClosestLocation = CurrentLocation; ClosestCombatPath = CombatPath; Found = true; } } if (Found) { - OutCombatPathLocation = ClosestLocation; OutCombatPath = ClosestCombatPath; - OutDistanceAlongSpline = OutCombatPath->Spline->GetDistanceAlongSplineAtSplineInputKey(ClosestKey); } return Found; } diff --git a/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h b/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h index 4b570a9..13e4f2c 100644 --- a/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h +++ b/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h @@ -19,7 +19,7 @@ protected: virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; public: - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Components") + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components") TObjectPtr Spline; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Combat Platformer Path") @@ -27,4 +27,7 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Combat Platformer Path") bool SwapCamera; + + UPROPERTY(Transient, BlueprintReadOnly) + TObjectPtr FlattenSpline; }; diff --git a/Pawn_Unreal/Source/Pawn/Public/GameplayModes/PwnGameplayModeSubsystem.h b/Pawn_Unreal/Source/Pawn/Public/GameplayModes/PwnGameplayModeSubsystem.h index a7b7334..0f3547a 100644 --- a/Pawn_Unreal/Source/Pawn/Public/GameplayModes/PwnGameplayModeSubsystem.h +++ b/Pawn_Unreal/Source/Pawn/Public/GameplayModes/PwnGameplayModeSubsystem.h @@ -41,9 +41,8 @@ public: UFUNCTION() void UnregisterCombatPath(APwnCombatPlatformerPath* CombatPath); - UFUNCTION() - bool FindClosestCombatPathLocation(const FVector& Location, FVector& OutCombatPathLocation, APwnCombatPlatformerPath*& OutCombatPath, - float& OutDistanceAlongSpline) const; + UFUNCTION(BlueprintCallable) + bool FindClosestCombatPathLocation(const FVector& Location, APwnCombatPlatformerPath*& OutCombatPath) const; public: UPROPERTY(BlueprintAssignable) diff --git a/Pawn_Unreal/Source/Pawn/Public/Utils/EngineUtils.h b/Pawn_Unreal/Source/Pawn/Public/Utils/EngineUtils.h index 16e9b2d..9ec6fc5 100644 --- a/Pawn_Unreal/Source/Pawn/Public/Utils/EngineUtils.h +++ b/Pawn_Unreal/Source/Pawn/Public/Utils/EngineUtils.h @@ -9,4 +9,13 @@ #define PRINT_STRING_GREEN(Content, ...) PRINT_STRING_GENERIC(FColor::Green, Content, __VA_ARGS__); #define BOOL_TO_TEXT(Bool) ((Bool) ? TEXT("True") : TEXT("False")) -#define BOOL_TO_STR(Bool) ((Bool) ? "True" : "False") \ No newline at end of file +#define BOOL_TO_STR(Bool) ((Bool) ? "True" : "False") + +#define IGNORE_OWNER_PARAMS GetIgnoreActorParams(GetOwner()) +#define IGNORE_THIS_PARAMS GetIgnoreActorParams(this) + +inline FCollisionQueryParams GetIgnoreActorParams(const AActor* Actor) { + FCollisionQueryParams Params; + Params.AddIgnoredActor(Actor); + return Params; +} \ No newline at end of file