How can I best use Rotation of FHitResult?

Hey! I am trying to create a script to allow me to check if the surface that the player has collided with is a wall, so that they can wall jump. Here is what I thought about doing:

//Get Collision Info
void AFPSCharacter::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if (Hit.Rotation > wJumpSteepness && CharacterMovement->IsMovingOnGround())
	{
		canWallJump = true;
	}
}

With Hit.Rotation replacing the steepness of the surface. Is this possible? If someone could help me with this, it would be much appreciated! Thank you in advance.

#ImpactNormal

What you want is

Hit.ImpactNormal

This is the Vector representing the facing direction of the surface at the point of impact, in world space

to get this as a rotation:

const FRotator SurfaceRotation = Hit.ImpactNormal.Rotation();

Just know this is in world space and you can decide what qualifies as a sufficient angle for wall jumping

for example

if you wanted all walls to be at elast 70 degrees from the flat ground plan (almost totally vertical)

you would do

const FRotator SurfaceRotation = Hit.ImpactNormal.Rotation();
if(FMath::Abs(SurfaceRotation.Pitch) > 70)
{
  //yes this is a wall jump
}

to make sure you are getting the numbers you expect

make sure to LOG or output this value so you can see it exactly

const FRotator SurfaceRotation = Hit.ImpactNormal.Rotation();

#Log / To Screen Wiki

Thank you very much (this is somewhat how it works in Unity as well)!

You’re welcome!

:slight_smile:

Rama