Download

How to get normal of a hit actor using a line trace?

Hello, I have a C++ function that ray casts a line out from the player. It then determines what kind of object was hit according to its collision channel.
I made a custom collision channel called “Door” which I apply to my door blueprint. In the door blueprint, I can open and close the hit door no problem (with timelines and such).

My question is, how can I determine what side the door was hit from so I can open the door different directions according to where the player is standing? Something like, “Side 1 hit” and “Side 2 Hit”

I noticed in C++ there is a HitResult.Location() function of type FVector Net_Quantize.I have no idea how to use this and cant find anything on NET_QUANTIZE.

thank you!

Just check out the full suite of options in FHitResult:

You can query the normal resulting from the sweep, query the normal from the impact itself, or if you really want, grab the actor that was hit and use information from that.

Hi there thanks for the answer. Ideally, I would like to get the hit location from the actor itself but cant figure out how. Iv’e never used any Net_Quantize functions and cant seem to get Normals() to work. Is there any additional setup needed for this? thanks

RecieveHit() in AActor seems good but it will not detect line traces :frowning:

Okay actually I just got ImpactNormals() and Normals() to work except I should be getting the same result on both sides of the door (Cube) right? I get different results when the door opens and closes. due to it being normals in World space i guess. I just want to detect what side of door is being hit :frowning: Im not a C++ wizard

You don’t need to be a C++ wizard to do this.

Get the door’s right vector. If your door is orientated with the door knob pointing in the X axis, you can get the door’s right vector by doing: GetTransform().GetUnitAxis(EAxis::Y);

Then you dot product the ImpactNormal() and the right vector of the door in world space. This will tell you the angle between the ImpactNormal() and the door’s orientation. From that you can dynamically figure out which side of the door the ray hit.

I think you should do some research on dot and cross product. Most game programming involves in-depth math and trigonometry knowledge.