How to detect which side relative location lies in

Greetings !

Okay I have a tank that uses complex collision body, and I am trying to know at which side the “missile” hit the tank (left, right, front, back). I am trying to achieving that via the Bounds of the collision body (which is Box bounds)

My current work flow:

1-Find relative location of the missile “Pos”

only that so far, couldn’t figure out a way to handle that without having extra colliders (one for each side).

Can anyone suggest anything? (Note that “Pos” can be inside the bounds)

Cheers and thanks

Hi snake,

Trace or collision event have world space collision position, hit component, hit actor. If you have multiple components, you can get from component name such as left armor you named. Otherwise, you can switch world position to relative position, if origin is center of actor, positive x axis is forward, positive y is right. So if x less than zero, it is back side, y less than zero is left side.

Cheers.
Omega

Thanks Omega for your answer.

still, lets say we got the relative hit location (x:5,y:-2), this can tell that the impact was in Front and Left, But wont give me the exact impact side (Front OR Left, not both).

I thought about using more collision boxes to indicate sides, but i have many tanks, which mean i will have to make sure of having 4 boxes per tank, aligned correctly based on the tank shape…very annoying work lol.

Okay, I solved it by using splitting the rectangle to 4 segments, and comparing closest distance between relative point to each segment using FMath::PointDistToSegmentSquared(), and it worked like a charm :smiley:

1 Like