From 828faa777c1fe1dda8e0e2403f99d36a04ab00b3 Mon Sep 17 00:00:00 2001 From: Maxime Date: Sat, 25 Nov 2023 16:50:06 +0100 Subject: [PATCH] Reculate flatten spline regulary --- Pawn_Unreal/Content/Characters/BP_Judy.uasset | 4 +- .../Input/BP_MainPlayerController.uasset | 4 +- .../2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset | 3 ++ .../3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset | 3 ++ .../4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset | 3 ++ .../6/68/OLXRTI84FNONTU2JDBX3TT.uasset | 3 ++ .../9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset | 3 ++ .../A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset | 3 ++ .../B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset | 2 +- .../D/CW/QYYSD12YDU0PI51J52Y2HA.uasset | 3 ++ .../E/9K/R7HQI0E9NM3G94LW522VPS.uasset | 4 +- .../F/5J/S6S8JM317CY89GHBX0Z8RT.uasset | 4 +- .../PwnCharacterMovementComponent.cpp | 38 +++++++++++----- .../Combat/PwnCombatPlatformerPath.cpp | 43 +++++++++++++------ .../PwnGameplayModeSubsystem.cpp | 14 ++++-- .../PwnCharacterMovementComponent.h | 4 +- .../Combat/PwnCombatPlatformerPath.h | 8 ++++ 17 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/6/68/OLXRTI84FNONTU2JDBX3TT.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/D/CW/QYYSD12YDU0PI51J52Y2HA.uasset diff --git a/Pawn_Unreal/Content/Characters/BP_Judy.uasset b/Pawn_Unreal/Content/Characters/BP_Judy.uasset index 950a4d3..17341d7 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:aaf2e79b6ee6dd330742de2c40b4c325f466a163eb0f7d597c47eb96567f8e35 -size 265173 +oid sha256:e823faf6a9b291aba6b45d09176f6aeb12ee86c5df400ec81243f4e450b21d39 +size 265412 diff --git a/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset b/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset index f27fa8d..79fca06 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:9626f55cfae07f9f58e1886f85cba00a69f9a8d0b52ff90d79fd8fa33838b85b -size 254476 +oid sha256:006349ce2600c49b80d4c41969188203c20e5e84e4cc946aeb059f34a32c5e5b +size 253364 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset new file mode 100644 index 0000000..808f9ca --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3d9192445808db12750e1d39f1ebec38ae921576138d257450a0f4a6c98658a +size 4450 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset new file mode 100644 index 0000000..6a49b4a --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:230c0778e3accca7d856a0e9512564eb1cbfcb23c7faaad91e58b22f38ac74d6 +size 4450 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset new file mode 100644 index 0000000..f84ad2c --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:261bf3b242e97e63be313d7bd335b4d98122d296b260626749631cde5ce4c552 +size 4564 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/6/68/OLXRTI84FNONTU2JDBX3TT.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/6/68/OLXRTI84FNONTU2JDBX3TT.uasset new file mode 100644 index 0000000..8d986f5 --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/6/68/OLXRTI84FNONTU2JDBX3TT.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:26e37d0cb0d850659f6655a9cbfd30b6b61bba34b11f2530aca60d172327a693 +size 4564 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset new file mode 100644 index 0000000..990bae9 --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01ce1de5072ec60abf38abbd5d688d7c72e5ec0ce610e79b180e486549acc888 +size 4450 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset new file mode 100644 index 0000000..0f43f95 --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de2e7c977dfdcb812e522aa8d2be820928877b8430622378d41abaecdb0e9a9d +size 4564 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset index d83af1a..bd47d19 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8726192ccd66b1de2dd6bf61c882c365fa753142a6e4bc55785234f2e3113512 +oid sha256:893fa142a08b01557d8d90f0a87d9cffa6bec9a4cf5e642f870c65b1f4c3c3e6 size 75333 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/D/CW/QYYSD12YDU0PI51J52Y2HA.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/D/CW/QYYSD12YDU0PI51J52Y2HA.uasset new file mode 100644 index 0000000..3d0bf3d --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/D/CW/QYYSD12YDU0PI51J52Y2HA.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb434dd91253050791872244219180b21f2e0e9e19258ec0704539aa21c57dc7 +size 4450 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/E/9K/R7HQI0E9NM3G94LW522VPS.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/E/9K/R7HQI0E9NM3G94LW522VPS.uasset index 7e35a6c..2823623 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/E/9K/R7HQI0E9NM3G94LW522VPS.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/E/9K/R7HQI0E9NM3G94LW522VPS.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:95bcb6662894f734b261087e9e5915e21390cbd89e2c77aba6881b3e0bc6ebd3 -size 214639 +oid sha256:e2a5c54375c8d6daa20cf68cbad330fa3194e7de05d853c415a3730f52daf51a +size 266884 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/F/5J/S6S8JM317CY89GHBX0Z8RT.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/F/5J/S6S8JM317CY89GHBX0Z8RT.uasset index d49e891..c7d8050 100644 --- a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/F/5J/S6S8JM317CY89GHBX0Z8RT.uasset +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/F/5J/S6S8JM317CY89GHBX0Z8RT.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6063cacf843ba2a94830c2b9acca9e870bade29249f7346621ca61863896ed65 -size 4450 +oid sha256:ceec573e8ae3631c2eddd638cbbcbaae04560933bd8f0708832ca809de87d4e4 +size 4564 diff --git a/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp b/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp index 58a6bf2..a2e3e9d 100644 --- a/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/Characters/PwnCharacterMovementComponent.cpp @@ -86,7 +86,7 @@ void UPwnCharacterMovementComponent::EnterSplineFollowMode() { IsFollowingSpline = true; SetMovementMode(MOVE_Custom, SplineWalking); - UpdateCurrentCombatPath(true); + UpdateCurrentCombatPath(true, true); } void UPwnCharacterMovementComponent::ExitSplineFollowMode() { @@ -99,25 +99,35 @@ bool UPwnCharacterMovementComponent::IsCustomMovementMode(const ECustomMovementM return MovementMode == MOVE_Custom && CustomMovementMode == Mode; } -bool UPwnCharacterMovementComponent::LineTraceToGround(FHitResult& OutHit, const FVector& StartLocation) const { +bool UPwnCharacterMovementComponent::LineTraceToGround(FHitResult& OutHit, const FVector& StartLocation, const FLinearColor& DebugColor) const { const FVector EndLocation = StartLocation + FVector(0.0f, 0.0f, -LineTraceDistance); return UKismetSystemLibrary::LineTraceSingle(this, StartLocation, EndLocation, UEngineTypes::ConvertToTraceType(ECC_Visibility), false, TArray(), - EDrawDebugTrace::None, OutHit, true, FLinearColor::Red, FLinearColor::Green, 0.5f); + DebugColor == FLinearColor::White ? EDrawDebugTrace::None : EDrawDebugTrace::ForDuration, OutHit, true, DebugColor, FLinearColor::Green, 0.5f); } - -void UPwnCharacterMovementComponent::UpdateCurrentCombatPath(const bool UpdateLocation) { +float AccumulatedTimer = 0.0f; +void UPwnCharacterMovementComponent::UpdateCurrentCombatPath(const bool Force, const bool UpdateLocation) { + AccumulatedTimer += GetWorld()->GetDeltaSeconds(); + if (AccumulatedTimer < 0.3f && !Force) { + return; + } + AccumulatedTimer = 0.0f; APwnCombatPlatformerPath* OutCombatPath; FHitResult Hit; - if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation()) + float ClosestInputKey = -1.0f; + if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation(), FLinearColor::Red)) { + UE_LOG(LogTemp, Log, TEXT("Hit location : %s"), *Hit.ImpactPoint.ToString()); + } + + if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation(), FLinearColor::Red) && UPwnGameplayModeSubsystem::Get(this).FindClosestCombatPathLocation(Hit.ImpactPoint, OutCombatPath) && OutCombatPath != CombatPath) { CombatPath = OutCombatPath; DotDirection = CombatPath->Reversed ? -1.0f : 1.0f; - const float ClosestInputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(UpdatedComponent->GetComponentLocation()); + ClosestInputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(UpdatedComponent->GetComponentLocation()); const FVector ClosestLocation = CombatPath->Spline->GetLocationAtSplineInputKey(ClosestInputKey, ESplineCoordinateSpace::World); - if (LineTraceToGround(Hit, ClosestLocation)) { + if (LineTraceToGround(Hit, ClosestLocation, FLinearColor::Blue)) { const float SplineKey = CombatPath->FlattenedSpline->FindInputKeyClosestToWorldLocation(Hit.ImpactPoint); DistanceAlongSpline = CombatPath->FlattenedSpline->GetDistanceAlongSplineAtSplineInputKey(SplineKey); @@ -128,6 +138,14 @@ void UPwnCharacterMovementComponent::UpdateCurrentCombatPath(const bool UpdateLo } } } + + check(CombatPath); + + // If the combat path was the same as before, the closest input key will has not been computed + if (ClosestInputKey < 0.0f) { + ClosestInputKey = CombatPath->Spline->FindInputKeyClosestToWorldLocation(UpdatedComponent->GetComponentLocation()); + } + CombatPath->UpdateFlattenSpline(ClosestInputKey); } void UPwnCharacterMovementComponent::UpdateTangentAndAcceleration() { @@ -163,7 +181,7 @@ void UPwnCharacterMovementComponent::UpdatePawnVelocity(const float TimeTick) { void UPwnCharacterMovementComponent::UpdateDistanceAlongSpline() { FHitResult Hit; - if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation())) { + if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation(), FLinearColor::White)) { const FVector ImpactPoint = Hit.ImpactPoint; const float InputKey = CombatPath->FlattenedSpline->FindInputKeyClosestToWorldLocation(ImpactPoint); DistanceAlongSpline = CombatPath->FlattenedSpline->GetDistanceAlongSplineAtSplineInputKey(InputKey); @@ -378,7 +396,7 @@ void UPwnCharacterMovementComponent::PhysSplineWalking(const float DeltaTime, in /* -- PAWN MODIFICATIONS -- */ UpdateDistanceAlongSpline(); - UpdateLocationOnFlattenedSpline(); + //UpdateLocationOnFlattenedSpline(); } void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, int32 Iterations) { diff --git a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp index f26c9c1..072bde4 100644 --- a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/Combat/PwnCombatPlatformerPath.cpp @@ -3,6 +3,8 @@ #include "Components/SplineComponent.h" #include "GameplayModes/PwnGameplayModeSubsystem.h" +constexpr int FlattenSplinePadding = 2; + APwnCombatPlatformerPath::APwnCombatPlatformerPath() { PrimaryActorTick.bCanEverTick = false; @@ -16,21 +18,26 @@ APwnCombatPlatformerPath::APwnCombatPlatformerPath() { #endif } -void APwnCombatPlatformerPath::BeginPlay() { - UPwnGameplayModeSubsystem* Subsystem = GetWorld()->GetSubsystem(); - check(Subsystem); - Subsystem->RegisterCombatPath(this); +void APwnCombatPlatformerPath::UpdateFlattenSpline(const float InputKey) { + const int32 SplinePointCounts = Spline->GetNumberOfSplinePoints(); + const int32 NewMinKey = FMath::Clamp(FMath::CeilToInt(InputKey) - FlattenSplinePadding, 0, SplinePointCounts - 1); + const int32 NewMaxKey = FMath::Clamp(FMath::FloorToInt(InputKey) + FlattenSplinePadding, 0, SplinePointCounts - 1); + + if (NewMinKey == MinKey && NewMaxKey == MaxKey) { + // Already up to date + return; + } + + MinKey = NewMinKey; + MaxKey = NewMaxKey; - FlattenedSpline = NewObject(this, TEXT("FlattenedSpline")); - FlattenedSpline->SetClosedLoop(Spline->IsClosedLoop(), false); - FlattenedSpline->ReparamStepsPerSegment = Spline->ReparamStepsPerSegment; FlattenedSpline->ClearSplinePoints(false); - const FVector FirstPointLocation = Spline->GetLocationAtSplinePoint(0, ESplineCoordinateSpace::World); + const FVector FirstPointLocation = Spline->GetLocationAtSplinePoint(MinKey, ESplineCoordinateSpace::World); const float FirstPointZ = FirstPointLocation.Z; - const int32 PointsCount = Spline->GetNumberOfSplinePoints(); - for (int i = 0; i < PointsCount; ++i) { + int32 PointIndex = 0; + for (int i = MinKey; i <= MaxKey; ++i, ++PointIndex) { FVector NewLocation = Spline->GetLocationAtSplinePoint(i, ESplineCoordinateSpace::World); NewLocation.Z = FirstPointZ; FlattenedSpline->AddSplinePoint(NewLocation, ESplineCoordinateSpace::World, false); @@ -40,11 +47,23 @@ void APwnCombatPlatformerPath::BeginPlay() { ArriveTangent.Z = 0; LeaveTangent.Z = 0; - FlattenedSpline->SetTangentsAtSplinePoint(i, ArriveTangent, LeaveTangent, ESplineCoordinateSpace::World, false); + FlattenedSpline->SetTangentsAtSplinePoint(PointIndex, ArriveTangent, LeaveTangent, ESplineCoordinateSpace::World, false); } FlattenedSpline->UpdateSpline(); - +} + +void APwnCombatPlatformerPath::BeginPlay() { + UPwnGameplayModeSubsystem* Subsystem = GetWorld()->GetSubsystem(); + check(Subsystem); + Subsystem->RegisterCombatPath(this); + + FlattenedSpline = NewObject(this, TEXT("FlattenedSpline")); + FlattenedSpline->SetClosedLoop(Spline->IsClosedLoop(), false); + FlattenedSpline->ReparamStepsPerSegment = Spline->ReparamStepsPerSegment; + + UpdateFlattenSpline(0.0f); + Super::BeginPlay(); } diff --git a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp index 9a4a120..b649aef 100644 --- a/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp +++ b/Pawn_Unreal/Source/Pawn/Private/GameplayModes/PwnGameplayModeSubsystem.cpp @@ -2,6 +2,7 @@ #include "Components/SplineComponent.h" #include "GameplayModes/Combat/PwnCombatPlatformerPath.h" +#include "Utils/EngineUtils.h" UPwnGameplayModeSubsystem& UPwnGameplayModeSubsystem::Get(const UObject* WorldContextObject) { const UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject); @@ -57,16 +58,21 @@ bool UPwnGameplayModeSubsystem::FindClosestCombatPathLocation(const FVector& Loc const float CurrentKey = CurrentSpline->FindInputKeyClosestToWorldLocation(Location); FVector CurrentLocation = CurrentSpline->GetLocationAtSplineInputKey(CurrentKey, ESplineCoordinateSpace::World); - const float CurrentDistance = FVector::DistSquared(Location, CurrentLocation); - if (CurrentDistance < ShortestDistance) { - ShortestDistance = CurrentDistance; - ClosestCombatPath = CombatPath; + if (CurrentLocation.Z < Location.Z) { + continue; } + const float CurrentDistance = FVector::DistSquared(Location, CurrentLocation); + if (CurrentDistance >= ShortestDistance) { + continue; + } + ShortestDistance = CurrentDistance; + ClosestCombatPath = CombatPath; } if (ClosestCombatPath != nullptr) { OutCombatPath = ClosestCombatPath; return true; } + PRINT_STRING_RED("Aie"); return false; } diff --git a/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h b/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h index 1203fa9..15c1dd3 100644 --- a/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h +++ b/Pawn_Unreal/Source/Pawn/Public/Characters/PwnCharacterMovementComponent.h @@ -51,9 +51,9 @@ public: bool IsCustomMovementMode(const ECustomMovementMode Mode) const; private: - bool LineTraceToGround(FHitResult& OutHit, const FVector& StartLocation) const; + bool LineTraceToGround(FHitResult& OutHit, const FVector& StartLocation, const FLinearColor& DebugColor) const; - void UpdateCurrentCombatPath(const bool UpdateLocation = false); + void UpdateCurrentCombatPath(bool Force = false, const bool UpdateLocation = false); /** * Updates the tangent in function of the current distance along the spline. Then updates the acceleration so it will simulate an input in the diff --git a/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h b/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h index bb4ad8a..2b86d75 100644 --- a/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h +++ b/Pawn_Unreal/Source/Pawn/Public/GameplayModes/Combat/PwnCombatPlatformerPath.h @@ -13,6 +13,8 @@ class PAWN_API APwnCombatPlatformerPath : public AActor { public: APwnCombatPlatformerPath(); + void UpdateFlattenSpline(const float InputKey); + protected: virtual void BeginPlay() override; @@ -30,4 +32,10 @@ public: UPROPERTY(Transient, BlueprintReadOnly) TObjectPtr FlattenedSpline; + + UPROPERTY() + int32 MinKey; + + UPROPERTY() + int32 MaxKey; };