# Minimum, smallest distance

**URL:** <https://forums.unrealengine.com/t/minimum-smallest-distance/486090>\
**Category:** World Creation\
**Tags:** Trace, box, unreal-engine, question\
**Created:** [July 12, 2021, 11:34am UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090 "2021-07-12T11:34:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Godlike0207](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Godlike0207](https://forums.unrealengine.com/u/Godlike0207)\
**Post date:** [July 12, 2021, 11:34am UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090/1 "2021-07-12T11:34:18Z")

</div>

The object should move in the direction closest to the wall. Unfortunately it didn’t work. How can I best implement this:

 ![343900-unbenannt.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/c/f/6cf50d89f7c3d731da45c48b24731f82302aaf37.png)

 ![343911-unbenannt-5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/7/b57ce2e34be61660babd7a27be2fd0e7c3ac2cf1.png)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 12, 2021, 12:01pm UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090/2 "2021-07-12T12:01:48Z")

</div>

You’re tracing only once, you should trace 4 times. Once in each direction.

---

<div class="post-metadata">

**Author:** ![L1z4rD89](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l1z4rd89/32/1194537_2.png) [@L1z4rD89](https://forums.unrealengine.com/u/L1z4rD89)\
**Post date:** [July 12, 2021, 12:08pm UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090/3 "2021-07-12T12:08:10Z")

</div>

Trace in all directions, set the Distance and the DeltaLocation for each direction (here 2 arrays) and then get the smallest value of the distance array and move into that direction.

 ![343880-move-direction.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/b/b1b96084d59a569f768436bbb0ba145b846ac152.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 12, 2021, 12:30pm UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090/4 "2021-07-12T12:30:07Z")

</div>

My take on this since there’s going to be as many ways as there are people; assumes a _Pawn_ + _Floating Pawn Movement_ comp for collision:

 ![343913-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/d/4/9d442daddaae7dbb8012ed75e95d9b0aa41a74cb.png)

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/2/0929310ebe117664a2875ceeb74e96a9787fc876.gif)](https://gyazo.com/2b723e15631e41652ccccb2ef148108e)

Does not currently account for other actors when measuring distance. Can be easily filtered with channels, though.

---

<div class="post-metadata">

**Author:** ![Godlike0207](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Godlike0207](https://forums.unrealengine.com/u/Godlike0207)\
**Post date:** [July 12, 2021, 12:37pm UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090/5 "2021-07-12T12:37:19Z")

</div>

Very Nice!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 12, 2021, 1:33pm UTC](https://forums.unrealengine.com/t/minimum-smallest-distance/486090/6 "2021-07-12T13:33:48Z")

</div>

I’ll just add that if the walls are not moving, this can be run _once_ rather than on Tick. No need to waste those precious cycles for trace looping. Depends on what’s needed, ofc.

And if you do not want to use sliding collision the pawn + movement comp offers but still need to stop short of reaching an obstacle, you can either calculate it from actor bounds or look into how _Sweep_ works. That’s providing you do not have collision covered already.

Good luck with rest!
