How To Check For Ground Beneath Pawn?

Hello there. The issue I’m having is checking for the ground beneath the player. To be clear, I am intentionally not using the charactermovementcomponent, only the pawn. The way I currently have it set up is to use oncomponenthit but it registers anytime anything collides with the player. How or what can I do to get it so that I only check for the ground beneath the player? I haven’t found any posts on this when searching online. Another detail is that the pawn I’m using is a longways box, kind of like a car so a raycast hasn’t been effective for this.

One way this might work is to check the ground touching actors every tick and return true if the touching actor is pawn. Try experimenting with and all that.

why wouldn’t a raycast work?

I don’t quite follow what you’re saying. Do you mean to have the ground itself check for the player? My issue is that I cannot distinguish collision from the direction they occur. Currently, any contact registers the player as touching the ground when using OnComponentHit when I need it to be only for collision occurring below.

The collision box that represents the player is long like a car so cases occur where the player is standing on a ledge and part of them is still touching the ground but the raycast is not.

Precisely. You could maintain an array of pawn characters touching the ground (TMap or something) and then query that array from Pawn to see if the bool value corresponding to the Pawn key is true or not.

You can try analyzing the NormalImpulse vector. If it is along positive z direction (you may have to consider some x-y plane tolerance) then the colliding object has to be ground. Who/what else can hit from below :smiley:

I’d recommend managing ground detection through the functions already provided through the character class instead of tracing for ground.

ACharacter::Landed, ACharacter::OnWalkingOffLedge_Implementation, and ACharacter::OnJumped are the only three functions you need to do this. If either OnWalkingOffLedge_Implementation or OnJumped is called, then you know the player is not on the ground. If Landed is called, then you know the player is on the ground and you get the ground’s hit result passed in as well.

I mistook pawn for character. Whoops. Still, you could replicate the functions that call OnJumped, OnWalkingOffLedge_Implementation, and Landed.


I’d trace instead of using a collision volume. Your start location would be just above the bottom extent of your collision, and your end location would be a little below that extent. If your trace hits an object then you probably have an object that you can stand on as ground. If you want even more accuracy with differentiating proper ground with something else like a box, you should create a custom trace channel and collision preset for the ground.

If you use a box trace with the same dimensions as your pawn’s collision (but vertically flat), you can also get the ImpactLocation if you want to know exactly where the ground hit the player’s base.