Filter wall collisions in UE5

If you did everything correct, you could see that if we hit the wall from any side, our capsule will react the same way. Even if you jump, you will see a message as well. It should not be like that. You could check it in our post here.

Before we start, let’s prepare small testing shooting range.

  • We need wall with small angle, on one side we can run, another one – not. Something like that:
  • As you can understand we should have possibility to run on right side, but not on a left one.

And one more cube

Why do we need it? I can tell you, because if you come to this side:

you will see that we have hit reaction, it should not be like that.

So, let’s start filter it!

Here you need some understanding about dot product. (In the nearest future we will have math explanation on our site). It means that we have to “compare” two vectors, one of them is surface normal, Z vector of it and vector of walkable surface, which we could get from GetCharachterMovement Function. Let’s see it in code.


void AWallRunCharacter::OnCapsuleHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
                  FVector NormalImpulse, const FHitResult& Hit)
   const FVector HitNormal = Hit.ImpactNormal;

   if(HitNormal.Z > GetCharacterMovement()->GetWalkableFloorZ() || HitNormal.Z < -0.01f)
   GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Blue, TEXT("Capsule has been hit"));

And try it again, you will see, that on surface where we could walk – no messages, when jump – no messages! Amazing!

Ok, if you still have questions about this, join our discord(link below)!