Use Box Trace By Channel To Set The Location and Extent Of A Box Collision.

I have been trying to set an extent for my box collision based on the results of a Box trace by channel. I can find the mid point fine, but I’m struggling with how to set the box extent correctly.

The Box Extent is always too long. If I divide by 2, its too small. In fact, if I divide by anything, it will make it the wrong size in different trace lengths.

Thanks for any help in advance.

EDIT* It does not necessarily need to be done with box trace, It can be be done with sphere or line trace instead. Just trying to figure out how to do one axis first.

Lower this value instead.

That is only affecting how far the trace will go. Changing it to a lower value only makes the trace go less distance. It’s still the same problem.

I have lowered the value to 1000. Its the same difference. The red boxes are the start and end of the trace. The yellow box is the box extent size its getting and setting my collision box to, which is always bigger than it should be.

Though you might get some slight offset as impact point takes into account the closest contact point so you might get some inter-penetration.

Alternatively in place of a box trace you could do a line trace.

Here you can see the trace impact point

To get a more accurate distance you would have to get the line parallel from the impact point to the actor rotation and then move that point along it’s axis to get to the center of the source of the ray. Still won’t give perfect results as it will cut the ray slightly short as the rotation is skewed.

1 Like

There green distance pin value is avaliable and you can directly use it to mark up the lenght of the extent. Just place that into the proper location axis. (X of the make vector in your original case).

1 Like

Thanks for the suggestion, unfortunately using distance is giving mixed results based on trace length.

I have made a modification to your suggestion and I have achieved the correct size for what I needed. Thank you very much for pointing me in the right direction.

Used a line trace instead of a box trace.