Location relative to specified normal - how to?

I hope that the picture explains everything. How the vector math would look like to implement that? Of course I already know how to trace downwards and I already have the hit location and hit normal, but I can’t figure out how to do the next trace (x distance on specified direction relative to hit normal)

I would be grateful for some hints!

1 Like

The Out Hit Normal of your hit that you get from your trace is a vector that is perpendicular to the plane that you collided with. Together with your Out Hit Location vector it describes the plane you collided with. We’ll call that plane Plane1 for fun.

If you take the Out Hit Normal and your original “1” vector, you can find the normal of the plane they both reside on by taking their cross product. Together with that some Out Hit Location this describes another plane we’ll call Plane 2.

If you can visualize it in your mind, the intersection of Plane1 and Plane2 is a line that represents the vector you are looking for!

Lucky for us, that intersection line happens to be perpendicular to the normal vectors of the two planes. So taking the cross product of the two normal vectors will give you the direction vector you want. If you end up pointing exactly backwards, then just reverse the order of the arguments in your cross product. Or multiply your vector by -1.

1 Like

Thanks for the explanation, but I can’t get how to determine this 2nd plane in blueprints… I mean which vector should I input into Cross Product node. The surface normal and the second normal that I don’t know how to get. Sorry, my brain is quite weak in math.

I’ve also found a similar question HERE - But maybe it works only in Unity, since it doesn’t work in my Unreal project (in my case the direction doesn’t change anything and every cast faces world 0,0,0 location)

You said you traced “downward”. How did you do that?

Downward trace in my case == trace from actor location + (0,0,0) to actor location + (0,0,-100), so it traces -100 on Z from actor location.

(I don’t know if ‘trace downward’ is a good word, maybe ‘trace down’ is more sufficent? My english still in development :slight_smile: )

Great, so your downward vector is (0, 0, -100) and so the normal of the second plane is CrossProduct( (0, 0, -100), OutHitNormal ).

Ok, so when I set LineTrace start to hitLocation and LineTrace end to CrossProduct( (0,0-100), hitNormal ) then every trace points towards world 0,0,0 location and I don’t know why:

The cross-product will give you a direction vector, which will probably be normalized (length of the vector will be 1cm). If you try to use a normalized direction vector as a location, they will all be within 1cm of (0, 0, 0).

Instead, draw a line from hitLocation to (hitLocation + (CrossProductResult * 100.0))

Ah now I get it!

Thank you for the help! :slight_smile: