# How to detect if vector is in bounding box extent?

**URL:** <https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 1, 2016, 12:26pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784 "2016-08-01T12:26:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tireless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tireless](https://forums.unrealengine.com/u/Tireless)\
**Post date:** [August 1, 2016, 12:26pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/1 "2016-08-01T12:26:33Z")

</div>

Hi,

I’m trying to figure out how to detect if a vector is inside a collision box or not. Is there already a function for this? If not any help, ideas on how to solve this would be greatly appreciated! 😃

---

<div class="post-metadata">

**Author:** ![Erasio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Erasio](https://forums.unrealengine.com/u/Erasio)\
**Post date:** [August 1, 2016, 1:32pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/2 "2016-08-01T13:32:50Z")

</div>

Not that I know of.

It kinda depends on what you need to know. If it’s for a single bounding box the math to check it is simple enough and I’d just do that on my own.

Otherwise you could try to create a collision sphere with a radius of 0.1 or something like that which can give you a list of all overlapping actors since it’s within the collision system. (sphere because it’s slightly cheaper resource wise and easy to setup).

Those are the two solutions I can think off from the top of my head.

---

<div class="post-metadata">

**Author:** ![Tireless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tireless](https://forums.unrealengine.com/u/Tireless)\
**Post date:** [August 1, 2016, 1:42pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/3 "2016-08-01T13:42:08Z")

</div>

Thanks! Ended up creating a custom collision object channel and creating collision boxes. Then i checked for overlap like you suggested. Works perfect!

---

<div class="post-metadata">

**Author:** ![NoobsDeSroobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobsDeSroobs](https://forums.unrealengine.com/u/NoobsDeSroobs)\
**Post date:** [August 1, 2016, 3:15pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/4 "2016-08-01T15:15:11Z")

</div>

You can check if the vector elements are between the vector elements representing the corners on each end of a diagonal line.

For example, you have a box defined by two vectors; StartVec and EndVec.

Then you have your vector MyVec. Assuming that they are in the same coordinate system you can check if

MyVec.x is between StartVec.x and EndVec.x  
MyVec.y is between StartVec.y and EndVec.y  
MyVec.z is between StartVec.z and EndVec.z

If these are all true then it is within the box.

---

<div class="post-metadata">

**Author:** ![Tireless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tireless](https://forums.unrealengine.com/u/Tireless)\
**Post date:** [August 1, 2016, 3:51pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/5 "2016-08-01T15:51:08Z")

</div>

Thanks I think I understand. Though I’m not sure how one would go about to get the start and end vectors from a collision volume.

---

<div class="post-metadata">

**Author:** ![NoobsDeSroobs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobsDeSroobs](https://forums.unrealengine.com/u/NoobsDeSroobs)\
**Post date:** [August 1, 2016, 3:56pm UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/6 "2016-08-01T15:56:04Z")

</div>

You can simply get the center vector and add the vector from the center to each corner. You get the center by using the node GetWorldLocation.

---

<div class="post-metadata">

**Author:** ![Tireless](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tireless](https://forums.unrealengine.com/u/Tireless)\
**Post date:** [August 2, 2016, 10:15am UTC](https://forums.unrealengine.com/t/how-to-detect-if-vector-is-in-bounding-box-extent/365784/7 "2016-08-02T10:15:31Z")

</div>

Okay thanks!
