diff --git a/GravityStomp/Content/Characters/BP_GSCharacter.uasset b/GravityStomp/Content/Characters/BP_GSCharacter.uasset index a860480..29d649f 100644 --- a/GravityStomp/Content/Characters/BP_GSCharacter.uasset +++ b/GravityStomp/Content/Characters/BP_GSCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1a20bf4e0000fdd14349a353a86d96527d2c5ad6b8be19185a631276b67d4e5e -size 114464 +oid sha256:3d914c1a048f668db85b7c63fb9913ba0f5c2f71f4fcdf797e356c65d63c9903 +size 105098 diff --git a/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.cpp b/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.cpp index 460d226..e684295 100644 --- a/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.cpp +++ b/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.cpp @@ -5,6 +5,7 @@ // UE includes #include "Components/CapsuleComponent.h" #include "GameFramework/Character.h" +#include "Kismet/KismetMathLibrary.h" // These are defined in CharacterMovementComponent.cpp and inaccessible here. Just copy and paste too make the PhysFalling work namespace CharacterMovementConstants @@ -596,6 +597,40 @@ bool UGSCharacterMovementComponent::IsWalkable(const FHitResult& Hit) const } +bool UGSCharacterMovementComponent::FloorSweepTest(FHitResult& OutHit, const FVector& Start, const FVector& End, + ECollisionChannel TraceChannel, const FCollisionShape& CollisionShape, const FCollisionQueryParams& Params, + const FCollisionResponseParams& ResponseParam) const +{ + bool bBlockingHit = false; + + if (!bUseFlatBaseForFloorChecks) + { + bool IsUp = FMath::Abs(CharacterUpDirection.Dot(FVector::UpVector)) > UE_KINDA_SMALL_NUMBER; + + FQuat Rot = UKismetMathLibrary::RotatorFromAxisAndAngle(FVector::ForwardVector, IsUp ? 0.0f : 90.0f).Quaternion(); + bBlockingHit = GetWorld()->SweepSingleByChannel(OutHit, Start, End, Rot, TraceChannel, CollisionShape, Params, ResponseParam); + } + else + { + // Test with a box that is enclosed by the capsule. + const float CapsuleRadius = CollisionShape.GetCapsuleRadius(); + const float CapsuleHeight = CollisionShape.GetCapsuleHalfHeight(); + const FCollisionShape BoxShape = FCollisionShape::MakeBox(FVector(CapsuleRadius * 0.707f, CapsuleRadius * 0.707f, CapsuleHeight)); + + // First test with the box rotated so the corners are along the major axes (ie rotated 45 degrees). + bBlockingHit = GetWorld()->SweepSingleByChannel(OutHit, Start, End, FQuat(FVector(0.f, 0.f, -1.f), UE_PI * 0.25f), TraceChannel, BoxShape, Params, ResponseParam); + + if (!bBlockingHit) + { + // Test again with the same box, not rotated. + OutHit.Reset(1.f, false); + bBlockingHit = GetWorld()->SweepSingleByChannel(OutHit, Start, End, FQuat::Identity, TraceChannel, BoxShape, Params, ResponseParam); + } + } + + return bBlockingHit; +} + void UGSCharacterMovementComponent::SetCharacterUpDirection(FVector NewUpDirection) { diff --git a/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.h b/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.h index da05fce..90cec3d 100644 --- a/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.h +++ b/GravityStomp/Source/GravityStompGame/Character/GSCharacterMovementComponent.h @@ -30,6 +30,8 @@ public: virtual bool IsValidLandingSpot(const FVector& CapsuleLocation, const FHitResult& Hit) const override; virtual bool IsWalkable(const FHitResult& Hit) const override; + + virtual bool FloorSweepTest(FHitResult& OutHit, const FVector& Start, const FVector& End, ECollisionChannel TraceChannel, const FCollisionShape& CollisionShape, const FCollisionQueryParams& Params, const FCollisionResponseParams& ResponseParam) const override; // End UCharacterMovementComponent interface private: