diff --git a/Source/PBCharacterMovement/Private/Character/PBPlayerCharacter.cpp b/Source/PBCharacterMovement/Private/Character/PBPlayerCharacter.cpp index 53f122a..3cfd656 100644 --- a/Source/PBCharacterMovement/Private/Character/PBPlayerCharacter.cpp +++ b/Source/PBCharacterMovement/Private/Character/PBPlayerCharacter.cpp @@ -117,6 +117,10 @@ void APBPlayerCharacter::GetLifetimeReplicatedProps(TArray& O void APBPlayerCharacter::ApplyDamageMomentum(float DamageTaken, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) { + if (!DamageEvent.DamageTypeClass) + { + return; + } UDamageType const* const DmgTypeCDO = DamageEvent.DamageTypeClass->GetDefaultObject(); if (GetCharacterMovement()) { diff --git a/Source/PBCharacterMovement/Private/Character/PBPlayerMovement.cpp b/Source/PBCharacterMovement/Private/Character/PBPlayerMovement.cpp index c9a30ea..8861e48 100644 --- a/Source/PBCharacterMovement/Private/Character/PBPlayerMovement.cpp +++ b/Source/PBCharacterMovement/Private/Character/PBPlayerMovement.cpp @@ -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) @@ -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 @@ -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 @@ -1028,19 +1013,19 @@ void UPBPlayerMovement::PlayMoveSound(const float DeltaTime) if (MoveSound) { - TArray MoveSoundCues; + const TArray>* 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); @@ -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; @@ -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; @@ -1151,7 +1136,7 @@ void UPBPlayerMovement::PlayJumpSound(const FHitResult& Hit, bool bJumped) return; } - const TArray& MoveSoundCues = bJumped ? MoveSound->GetJumpSounds() : MoveSound->GetLandSounds(); + const TArray>& MoveSoundCues = bJumped ? MoveSound->GetJumpSounds() : MoveSound->GetLandSounds(); if (MoveSoundCues.Num() < 1) { @@ -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; diff --git a/Source/PBCharacterMovement/Public/Character/PBPlayerMovement.h b/Source/PBCharacterMovement/Public/Character/PBPlayerMovement.h index 3ed828e..dfa9096 100644 --- a/Source/PBCharacterMovement/Public/Character/PBPlayerMovement.h +++ b/Source/PBCharacterMovement/Public/Character/PBPlayerMovement.h @@ -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") @@ -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; diff --git a/Source/PBCharacterMovement/Public/Sound/PBMoveStepSound.h b/Source/PBCharacterMovement/Public/Sound/PBMoveStepSound.h index b1c664b..cf3c8ba 100644 --- a/Source/PBCharacterMovement/Public/Sound/PBMoveStepSound.h +++ b/Source/PBCharacterMovement/Public/Sound/PBMoveStepSound.h @@ -22,22 +22,22 @@ class PBCHARACTERMOVEMENT_API UPBMoveStepSound : public UObject TEnumAsByte GetSurfaceMaterial() const { return SurfaceMaterial; } UFUNCTION() - TArray GetStepLeftSounds() const { return StepLeftSounds; } + const TArray>& GetStepLeftSounds() const { return StepLeftSounds; } UFUNCTION() - TArray GetStepRightSounds() const { return StepRightSounds; } + const TArray>& GetStepRightSounds() const { return StepRightSounds; } UFUNCTION() - TArray GetSprintLeftSounds() const { return SprintLeftSounds; } + const TArray>& GetSprintLeftSounds() const { return SprintLeftSounds; } UFUNCTION() - TArray GetSprintRightSounds() const { return SprintRightSounds; } + const TArray>& GetSprintRightSounds() const { return SprintRightSounds; } UFUNCTION() - TArray GetJumpSounds() const { return JumpSounds; } + const TArray>& GetJumpSounds() const { return JumpSounds; } UFUNCTION() - TArray GetLandSounds() const { return LandSounds; } + const TArray>& GetLandSounds() const { return LandSounds; } UFUNCTION() float GetWalkVolume() const { return WalkVolume; }