Refactor CMC and fix camera combat path reference
This commit is contained in:
parent
aedd5ee35e
commit
f4f39995a5
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/Systems/Camera/BP_MainCameraManager.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Systems/Camera/BP_MainCameraManager.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/0/GT/B3FVEW201B4H0JZT407R3G.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/0/GT/B3FVEW201B4H0JZT407R3G.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/9/RQ/JYNZEWOG6SXNE3HGUCSZIE.uasset
(Stored with Git LFS)
Binary file not shown.
@ -86,32 +86,12 @@ void UPwnCharacterMovementComponent::EnterSplineFollowMode() {
|
|||||||
IsFollowingSpline = true;
|
IsFollowingSpline = true;
|
||||||
SetMovementMode(MOVE_Custom, SplineWalking);
|
SetMovementMode(MOVE_Custom, SplineWalking);
|
||||||
|
|
||||||
const UPwnGameplayModeSubsystem* Subsystem = GetWorld()->GetSubsystem<UPwnGameplayModeSubsystem>();
|
UpdateCurrentCombatPath(true);
|
||||||
check(Subsystem);
|
|
||||||
|
|
||||||
|
|
||||||
APwnCombatPlatformerPath* OutCombatPath;
|
|
||||||
if (Subsystem->FindClosestCombatPathLocation(UpdatedComponent->GetComponentLocation(), OutCombatPath)) {
|
|
||||||
CombatPath = OutCombatPath;
|
|
||||||
DotDirection = CombatPath->Reversed ? -1.0f : 1.0f;
|
|
||||||
|
|
||||||
const 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, -LineTraceDistance),
|
|
||||||
ECC_Visibility, IGNORE_OWNER_PARAMS)) {
|
|
||||||
const float SplineKey = CombatPath->FlattenedSpline->FindInputKeyClosestToWorldLocation(Hit.ImpactPoint);
|
|
||||||
DistanceAlongSpline = CombatPath->FlattenedSpline->GetDistanceAlongSplineAtSplineInputKey(SplineKey);
|
|
||||||
|
|
||||||
ClosestLocation.Z += CharacterOwner->GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
|
|
||||||
UpdatedComponent->SetWorldLocation(ClosestLocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UPwnCharacterMovementComponent::ExitSplineFollowMode() {
|
void UPwnCharacterMovementComponent::ExitSplineFollowMode() {
|
||||||
IsFollowingSpline = false;
|
IsFollowingSpline = false;
|
||||||
|
CombatPath = nullptr;
|
||||||
SetMovementMode(MOVE_Walking);
|
SetMovementMode(MOVE_Walking);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +99,36 @@ bool UPwnCharacterMovementComponent::IsCustomMovementMode(const ECustomMovementM
|
|||||||
return MovementMode == MOVE_Custom && CustomMovementMode == Mode;
|
return MovementMode == MOVE_Custom && CustomMovementMode == Mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UPwnCharacterMovementComponent::LineTraceToGround(FHitResult& OutHit, const FVector& StartLocation) const {
|
||||||
|
const FVector EndLocation = StartLocation + FVector(0.0f, 0.0f, -LineTraceDistance);
|
||||||
|
return GetWorld()->LineTraceSingleByChannel(OutHit, StartLocation, EndLocation, ECC_Visibility, IGNORE_OWNER_PARAMS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UPwnCharacterMovementComponent::UpdateCurrentCombatPath(const bool UpdateLocation) {
|
||||||
|
APwnCombatPlatformerPath* OutCombatPath;
|
||||||
|
FHitResult Hit;
|
||||||
|
if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation())
|
||||||
|
&& 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());
|
||||||
|
const FVector ClosestLocation = CombatPath->Spline->GetLocationAtSplineInputKey(ClosestInputKey, ESplineCoordinateSpace::World);
|
||||||
|
|
||||||
|
if (LineTraceToGround(Hit, ClosestLocation)) {
|
||||||
|
const float SplineKey = CombatPath->FlattenedSpline->FindInputKeyClosestToWorldLocation(Hit.ImpactPoint);
|
||||||
|
DistanceAlongSpline = CombatPath->FlattenedSpline->GetDistanceAlongSplineAtSplineInputKey(SplineKey);
|
||||||
|
|
||||||
|
if (UpdateLocation) {
|
||||||
|
FVector NewLocation = Hit.ImpactPoint;
|
||||||
|
NewLocation.Z += CharacterOwner->GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
|
||||||
|
UpdatedComponent->SetWorldLocation(NewLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UPwnCharacterMovementComponent::UpdateTangentAndAcceleration() {
|
void UPwnCharacterMovementComponent::UpdateTangentAndAcceleration() {
|
||||||
Tangent2D = CombatPath->FlattenedSpline->GetTangentAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World).GetSafeNormal2D();
|
Tangent2D = CombatPath->FlattenedSpline->GetTangentAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::World).GetSafeNormal2D();
|
||||||
// Recalculate acceleration so the input is relative to the spline
|
// Recalculate acceleration so the input is relative to the spline
|
||||||
@ -150,9 +160,7 @@ void UPwnCharacterMovementComponent::UpdatePawnVelocity(const float TimeTick) {
|
|||||||
|
|
||||||
void UPwnCharacterMovementComponent::UpdateDistanceAlongSpline() {
|
void UPwnCharacterMovementComponent::UpdateDistanceAlongSpline() {
|
||||||
FHitResult Hit;
|
FHitResult Hit;
|
||||||
if (GetWorld()->LineTraceSingleByChannel(Hit, UpdatedComponent->GetComponentLocation(),
|
if (LineTraceToGround(Hit, UpdatedComponent->GetComponentLocation())) {
|
||||||
UpdatedComponent->GetComponentLocation() + FVector(0.0f, 0.0f, -LineTraceDistance),
|
|
||||||
ECC_Visibility, IGNORE_OWNER_PARAMS)) {
|
|
||||||
const FVector ImpactPoint = Hit.ImpactPoint;
|
const FVector ImpactPoint = Hit.ImpactPoint;
|
||||||
const float InputKey = CombatPath->FlattenedSpline->FindInputKeyClosestToWorldLocation(ImpactPoint);
|
const float InputKey = CombatPath->FlattenedSpline->FindInputKeyClosestToWorldLocation(ImpactPoint);
|
||||||
DistanceAlongSpline = CombatPath->FlattenedSpline->GetDistanceAlongSplineAtSplineInputKey(InputKey);
|
DistanceAlongSpline = CombatPath->FlattenedSpline->GetDistanceAlongSplineAtSplineInputKey(InputKey);
|
||||||
@ -171,6 +179,8 @@ void UPwnCharacterMovementComponent::PhysSplineWalking(const float DeltaTime, in
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateCurrentCombatPath(); /* -- PAWN MODIFICATIONS -- */
|
||||||
|
|
||||||
if (!CharacterOwner || (!CharacterOwner->Controller && !bRunPhysicsWithNoController && !HasAnimRootMotion() && !CurrentRootMotion.
|
if (!CharacterOwner || (!CharacterOwner->Controller && !bRunPhysicsWithNoController && !HasAnimRootMotion() && !CurrentRootMotion.
|
||||||
HasOverrideVelocity() && (CharacterOwner->GetLocalRole() != ROLE_SimulatedProxy))) {
|
HasOverrideVelocity() && (CharacterOwner->GetLocalRole() != ROLE_SimulatedProxy))) {
|
||||||
Acceleration = FVector::ZeroVector;
|
Acceleration = FVector::ZeroVector;
|
||||||
@ -368,13 +378,12 @@ void UPwnCharacterMovementComponent::PhysSplineWalking(const float DeltaTime, in
|
|||||||
UpdateLocationOnFlattenedSpline();
|
UpdateLocationOnFlattenedSpline();
|
||||||
}
|
}
|
||||||
|
|
||||||
UE_DISABLE_OPTIMIZATION
|
|
||||||
|
|
||||||
void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, int32 Iterations) {
|
void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, int32 Iterations) {
|
||||||
if (DeltaTime < MIN_TICK_TIME) {
|
if (DeltaTime < MIN_TICK_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateCurrentCombatPath(); /* -- PAWN MODIFICATIONS -- */
|
||||||
UpdateTangentAndAcceleration(); /* -- PAWN MODIFICATIONS -- */
|
UpdateTangentAndAcceleration(); /* -- PAWN MODIFICATIONS -- */
|
||||||
|
|
||||||
FVector FallAcceleration = GetFallingLateralAcceleration(DeltaTime);
|
FVector FallAcceleration = GetFallingLateralAcceleration(DeltaTime);
|
||||||
@ -579,8 +588,6 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in
|
|||||||
: NewVelocity;
|
: NewVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
//UpdatePawnVelocity(TimeTick); /* -- PAWN MODIFICATIONS -- */
|
|
||||||
|
|
||||||
if (SubTimeTickRemaining > UE_KINDA_SMALL_NUMBER && (Delta | Adjusted) > 0.f) {
|
if (SubTimeTickRemaining > UE_KINDA_SMALL_NUMBER && (Delta | Adjusted) > 0.f) {
|
||||||
// Move in deflected direction.
|
// Move in deflected direction.
|
||||||
SafeMoveUpdatedComponent(Delta, PawnRotation, true, Hit);
|
SafeMoveUpdatedComponent(Delta, PawnRotation, true, Hit);
|
||||||
@ -631,7 +638,6 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in
|
|||||||
Velocity = HasAnimRootMotion() || CurrentRootMotion.HasOverrideVelocityWithIgnoreZAccumulate()
|
Velocity = HasAnimRootMotion() || CurrentRootMotion.HasOverrideVelocityWithIgnoreZAccumulate()
|
||||||
? FVector(Velocity.X, Velocity.Y, NewVelocity.Z)
|
? FVector(Velocity.X, Velocity.Y, NewVelocity.Z)
|
||||||
: NewVelocity;
|
: NewVelocity;
|
||||||
//UpdatePawnVelocity(TimeTick); /* -- PAWN MODIFICATIONS -- */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bDitch=true means that pawn is straddling two slopes, neither of which it can stand on
|
// bDitch=true means that pawn is straddling two slopes, neither of which it can stand on
|
||||||
@ -661,8 +667,6 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in
|
|||||||
Velocity.Y += 0.25f * GetMaxSpeed() * (RandomStream.FRand() - 0.5f);
|
Velocity.Y += 0.25f * GetMaxSpeed() * (RandomStream.FRand() - 0.5f);
|
||||||
Velocity.Z = FMath::Max<float>(JumpZVelocity * 0.25f, 1.f);
|
Velocity.Z = FMath::Max<float>(JumpZVelocity * 0.25f, 1.f);
|
||||||
|
|
||||||
//UpdatePawnVelocity(TimeTick); /* -- PAWN MODIFICATIONS -- */
|
|
||||||
|
|
||||||
Delta = Velocity * TimeTick;
|
Delta = Velocity * TimeTick;
|
||||||
|
|
||||||
SafeMoveUpdatedComponent(Delta, PawnRotation, true, Hit);
|
SafeMoveUpdatedComponent(Delta, PawnRotation, true, Hit);
|
||||||
@ -683,5 +687,3 @@ void UPwnCharacterMovementComponent::PhysSplineFalling(const float DeltaTime, in
|
|||||||
UpdateDistanceAlongSpline();
|
UpdateDistanceAlongSpline();
|
||||||
UpdateLocationOnFlattenedSpline();
|
UpdateLocationOnFlattenedSpline();
|
||||||
}
|
}
|
||||||
|
|
||||||
UE_ENABLE_OPTIMIZATION
|
|
||||||
|
|||||||
@ -3,6 +3,13 @@
|
|||||||
#include "Components/SplineComponent.h"
|
#include "Components/SplineComponent.h"
|
||||||
#include "GameplayModes/Combat/PwnCombatPlatformerPath.h"
|
#include "GameplayModes/Combat/PwnCombatPlatformerPath.h"
|
||||||
|
|
||||||
|
UPwnGameplayModeSubsystem& UPwnGameplayModeSubsystem::Get(const UObject* WorldContextObject) {
|
||||||
|
const UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject);
|
||||||
|
UPwnGameplayModeSubsystem* GameplayModeSubsystem = World->GetSubsystem<UPwnGameplayModeSubsystem>();
|
||||||
|
check(GameplayModeSubsystem);
|
||||||
|
return *GameplayModeSubsystem;
|
||||||
|
}
|
||||||
|
|
||||||
void UPwnGameplayModeSubsystem::Initialize(FSubsystemCollectionBase& Collection) {
|
void UPwnGameplayModeSubsystem::Initialize(FSubsystemCollectionBase& Collection) {
|
||||||
Super::Initialize(Collection);
|
Super::Initialize(Collection);
|
||||||
CurrentGameplayMode = EPwnGameplayMode::Narrative;
|
CurrentGameplayMode = EPwnGameplayMode::Narrative;
|
||||||
|
|||||||
@ -51,6 +51,10 @@ public:
|
|||||||
bool IsCustomMovementMode(const ECustomMovementMode Mode) const;
|
bool IsCustomMovementMode(const ECustomMovementMode Mode) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool LineTraceToGround(FHitResult& OutHit, const FVector& StartLocation) const;
|
||||||
|
|
||||||
|
void UpdateCurrentCombatPath(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
|
* Updates the tangent in function of the current distance along the spline. Then updates the acceleration so it will simulate an input in the
|
||||||
* direction of the tangent.
|
* direction of the tangent.
|
||||||
|
|||||||
@ -19,6 +19,8 @@ class PAWN_API UPwnGameplayModeSubsystem : public UWorldSubsystem {
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static UPwnGameplayModeSubsystem& Get(const UObject* WorldContextObject);
|
||||||
|
|
||||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||||
|
|
||||||
virtual void Deinitialize() override;
|
virtual void Deinitialize() override;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user