Reculate flatten spline regulary
This commit is contained in:
parent
6bf80a916e
commit
828faa777c
BIN
Pawn_Unreal/Content/Characters/BP_Judy.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Characters/BP_Judy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/2/CT/UPHK5BUH8DNIQJS4UO1KRN.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/3/Q3/8JE1YQQUKRW395C5OQTYX6.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/WE/HDY3CU9X91TC9CFXU6EMAV.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/6/68/OLXRTI84FNONTU2JDBX3TT.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/6/68/OLXRTI84FNONTU2JDBX3TT.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/6L/V7TKQC0TDFP9LCGD7LQIAN.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/A/CT/SK8HOOUE2UW1NZT9F7DL66.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/B/PJ/SG13J7WCZ1GL1Q1DWQNE8E.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/D/CW/QYYSD12YDU0PI51J52Y2HA.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/D/CW/QYYSD12YDU0PI51J52Y2HA.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/E/9K/R7HQI0E9NM3G94LW522VPS.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/E/9K/R7HQI0E9NM3G94LW522VPS.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/F/5J/S6S8JM317CY89GHBX0Z8RT.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/F/5J/S6S8JM317CY89GHBX0Z8RT.uasset
(Stored with Git LFS)
Binary file not shown.
@ -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<AActor*>(),
|
||||
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) {
|
||||
|
||||
@ -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<UPwnGameplayModeSubsystem>();
|
||||
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<USplineComponent>(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<UPwnGameplayModeSubsystem>();
|
||||
check(Subsystem);
|
||||
Subsystem->RegisterCombatPath(this);
|
||||
|
||||
FlattenedSpline = NewObject<USplineComponent>(this, TEXT("FlattenedSpline"));
|
||||
FlattenedSpline->SetClosedLoop(Spline->IsClosedLoop(), false);
|
||||
FlattenedSpline->ReparamStepsPerSegment = Spline->ReparamStepsPerSegment;
|
||||
|
||||
UpdateFlattenSpline(0.0f);
|
||||
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<USplineComponent> FlattenedSpline;
|
||||
|
||||
UPROPERTY()
|
||||
int32 MinKey;
|
||||
|
||||
UPROPERTY()
|
||||
int32 MaxKey;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user