Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ void APBPlayerCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& O

void APBPlayerCharacter::ApplyDamageMomentum(float DamageTaken, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser)
{
if (!DamageEvent.DamageTypeClass)
{
return;
}
UDamageType const* const DmgTypeCDO = DamageEvent.DamageTypeClass->GetDefaultObject<UDamageType>();
if (GetCharacterMovement())
{
Expand Down
54 changes: 22 additions & 32 deletions Source/PBCharacterMovement/Private/Character/PBPlayerMovement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,21 +355,6 @@ float UPBPlayerMovement::GetFallSpeed(bool bAfterLand)
return -FallVelocity.Z;
}

void UPBPlayerMovement::TwoWallAdjust(FVector& Delta, const FHitResult& Hit, const FVector& OldHitNormal) const
{
Super::TwoWallAdjust(Delta, Hit, OldHitNormal);
}

float UPBPlayerMovement::SlideAlongSurface(const FVector& Delta, float Time, const FVector& Normal, FHitResult& Hit, bool bHandleImpact)
{
return Super::SlideAlongSurface(Delta, Time, Normal, Hit, bHandleImpact);
}

FVector UPBPlayerMovement::ComputeSlideVector(const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const
{
return Super::ComputeSlideVector(Delta, Time, Normal, Hit);
}

FVector UPBPlayerMovement::HandleSlopeBoosting(const FVector& SlideResult, const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const
{
if (IsOnLadder() || bCheatFlying)
Expand Down Expand Up @@ -412,7 +397,12 @@ bool UPBPlayerMovement::ShouldCatchAir(const FFindFloorResult& OldFloor, const F
const float OldSurfaceFriction = GetFrictionFromHit(OldFloor.HitResult);

// As we get faster, make our speed multiplier smaller (so it scales with smaller friction)
const float SpeedMult = SpeedMultMax / Velocity.Size2D();
const float Speed2D = Velocity.Size2D();
if (Speed2D < KINDA_SMALL_NUMBER)
{
return false;
}
const float SpeedMult = SpeedMultMax / Speed2D;
const bool bSliding = OldSurfaceFriction * SpeedMult < 0.5f;

// See if we got less steep or are continuing at the same slope
Expand All @@ -439,11 +429,6 @@ bool UPBPlayerMovement::ShouldCatchAir(const FFindFloorResult& OldFloor, const F
return Super::ShouldCatchAir(OldFloor, NewFloor);
}

bool UPBPlayerMovement::IsWithinEdgeTolerance(const FVector& CapsuleLocation, const FVector& TestImpactPoint, const float CapsuleRadius) const
{
return Super::IsWithinEdgeTolerance(CapsuleLocation, TestImpactPoint, CapsuleRadius);
}

bool UPBPlayerMovement::ShouldCheckForValidLandingSpot(float DeltaTime, const FVector& Delta, const FHitResult& Hit) const
{
// TODO: check for flat base valid landing spots? at the moment this check is too generous for the capsule hemisphere
Expand Down Expand Up @@ -1028,19 +1013,19 @@ void UPBPlayerMovement::PlayMoveSound(const float DeltaTime)

if (MoveSound)
{
TArray<USoundCue*> MoveSoundCues;
const TArray<TObjectPtr<USoundCue>>* MoveSoundCues = nullptr;

if (bSprinting && !IsOnLadder())
{
MoveSoundCues = StepSide ? MoveSound->GetSprintLeftSounds() : MoveSound->GetSprintRightSounds();
MoveSoundCues = StepSide ? &MoveSound->GetSprintLeftSounds() : &MoveSound->GetSprintRightSounds();
}
if (!bSprinting || IsOnLadder() || MoveSoundCues.Num() < 1)
if (!MoveSoundCues || MoveSoundCues->Num() < 1)
{
MoveSoundCues = StepSide ? MoveSound->GetStepLeftSounds() : MoveSound->GetStepRightSounds();
MoveSoundCues = StepSide ? &MoveSound->GetStepLeftSounds() : &MoveSound->GetStepRightSounds();
}

// Error handling - Sounds not valid
if (MoveSoundCues.Num() < 1) // Sounds array not valid
if (MoveSoundCues->Num() < 1) // Sounds array not valid
{
// Get default sounds
MoveSound = GetMoveStepSoundBySurface(SurfaceType_Default);
Expand All @@ -1053,18 +1038,18 @@ void UPBPlayerMovement::PlayMoveSound(const float DeltaTime)
if (bSprinting)
{
// Get default sprint sounds
MoveSoundCues = StepSide ? MoveSound->GetSprintLeftSounds() : MoveSound->GetSprintRightSounds();
MoveSoundCues = StepSide ? &MoveSound->GetSprintLeftSounds() : &MoveSound->GetSprintRightSounds();
}

if (!bSprinting || MoveSoundCues.Num() < 1)
if (!MoveSoundCues || MoveSoundCues->Num() < 1)
{
// If bSprinting = true, the code enter this IF only if the updated MoveSoundCues with default sprint sounds is not valid (length < 1)
// If bSprinting = false, the code enter this IF because the walk sounds are not valid and must try to pick them from the default surface
// Get default walk sounds
MoveSoundCues = StepSide ? MoveSound->GetStepLeftSounds() : MoveSound->GetStepRightSounds();
MoveSoundCues = StepSide ? &MoveSound->GetStepLeftSounds() : &MoveSound->GetStepRightSounds();
}

if (MoveSoundCues.Num() < 1)
if (MoveSoundCues->Num() < 1)
{
// SurfaceType_Default sounds not found, return
return;
Expand All @@ -1073,7 +1058,7 @@ void UPBPlayerMovement::PlayMoveSound(const float DeltaTime)

// Sound array is valid, play a sound
// If the array has just one element pick that one skipping random
USoundCue* Sound = MoveSoundCues[MoveSoundCues.Num() == 1 ? 0 : FMath::RandRange(0, MoveSoundCues.Num() - 1)];
USoundCue* Sound = (*MoveSoundCues)[MoveSoundCues->Num() == 1 ? 0 : FMath::RandRange(0, MoveSoundCues->Num() - 1)];

Sound->VolumeMultiplier = MoveSoundVolume;

Expand Down Expand Up @@ -1151,7 +1136,7 @@ void UPBPlayerMovement::PlayJumpSound(const FHitResult& Hit, bool bJumped)
return;
}

const TArray<USoundCue*>& MoveSoundCues = bJumped ? MoveSound->GetJumpSounds() : MoveSound->GetLandSounds();
const TArray<TObjectPtr<USoundCue>>& MoveSoundCues = bJumped ? MoveSound->GetJumpSounds() : MoveSound->GetLandSounds();

if (MoveSoundCues.Num() < 1)
{
Expand Down Expand Up @@ -1881,6 +1866,11 @@ float UPBPlayerMovement::GetMaxSpeed() const
return Super::GetMaxSpeed();
}

if (!PBPlayerCharacter)
{
return Super::GetMaxSpeed();
}

if (bCheatFlying)
{
return (PBPlayerCharacter->IsSprinting() ? SprintSpeed : WalkSpeed) * 1.5f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PBCHARACTERMOVEMENT_API UPBPlayerMovement : public UCharacterMovementCompo

/** apply edge friction when crouching, even if not braking */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Movement: Walking")
float bEdgeFrictionAlwaysWhenCrouching;
bool bEdgeFrictionAlwaysWhenCrouching;

/** Time the player has before applying friction. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Movement: Jumping / Falling")
Expand Down Expand Up @@ -285,12 +285,8 @@ class PBCHARACTERMOVEMENT_API UPBPlayerMovement : public UCharacterMovementCompo
/** If the crouch lock should be toggled on or off, crouch lock locks the player in their crouch state */
void ToggleCrouchLock(bool bLock);

void TwoWallAdjust(FVector& OutDelta, const FHitResult& Hit, const FVector& OldHitNormal) const override;
float SlideAlongSurface(const FVector& Delta, float Time, const FVector& Normal, FHitResult& Hit, bool bHandleImpact = false) override;
FVector ComputeSlideVector(const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const override;
FVector HandleSlopeBoosting(const FVector& SlideResult, const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const override;
bool ShouldCatchAir(const FFindFloorResult& OldFloor, const FFindFloorResult& NewFloor) override;
bool IsWithinEdgeTolerance(const FVector& CapsuleLocation, const FVector& TestImpactPoint, const float CapsuleRadius) const override;
bool ShouldCheckForValidLandingSpot(float DeltaTime, const FVector& Delta, const FHitResult& Hit) const override;
void HandleImpact(const FHitResult& Hit, float TimeSlice = 0.0f, const FVector& MoveDelta = FVector::ZeroVector) override;
bool IsValidLandingSpot(const FVector& CapsuleLocation, const FHitResult& Hit) const override;
Expand Down
12 changes: 6 additions & 6 deletions Source/PBCharacterMovement/Public/Sound/PBMoveStepSound.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ class PBCHARACTERMOVEMENT_API UPBMoveStepSound : public UObject
TEnumAsByte<EPhysicalSurface> GetSurfaceMaterial() const { return SurfaceMaterial; }

UFUNCTION()
TArray<USoundCue*> GetStepLeftSounds() const { return StepLeftSounds; }
const TArray<TObjectPtr<USoundCue>>& GetStepLeftSounds() const { return StepLeftSounds; }

UFUNCTION()
TArray<USoundCue*> GetStepRightSounds() const { return StepRightSounds; }
const TArray<TObjectPtr<USoundCue>>& GetStepRightSounds() const { return StepRightSounds; }

UFUNCTION()
TArray<USoundCue*> GetSprintLeftSounds() const { return SprintLeftSounds; }
const TArray<TObjectPtr<USoundCue>>& GetSprintLeftSounds() const { return SprintLeftSounds; }

UFUNCTION()
TArray<USoundCue*> GetSprintRightSounds() const { return SprintRightSounds; }
const TArray<TObjectPtr<USoundCue>>& GetSprintRightSounds() const { return SprintRightSounds; }

UFUNCTION()
TArray<USoundCue*> GetJumpSounds() const { return JumpSounds; }
const TArray<TObjectPtr<USoundCue>>& GetJumpSounds() const { return JumpSounds; }

UFUNCTION()
TArray<USoundCue*> GetLandSounds() const { return LandSounds; }
const TArray<TObjectPtr<USoundCue>>& GetLandSounds() const { return LandSounds; }

UFUNCTION()
float GetWalkVolume() const { return WalkVolume; }
Expand Down