# How do I calculate when a character is within an angle?

**URL:** <https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 11, 2022, 1:39am UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783 "2022-10-11T01:39:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![captainTvZs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/captaintvzs/32/580097_2.png) [@captainTvZs](https://forums.unrealengine.com/u/captainTvZs)\
**Post date:** [October 11, 2022, 1:39am UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783/1 "2022-10-11T01:39:35Z")

</div>

I hope I was able to explain.

How do I calculate if my character is in an angle? Player1 in the image is in an acceptable position. Player2’s location is not accepted.

![Adsız](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/6/7/067ed0f509e436e6dcd469204a19731b147e6e00.png)

---

<div class="post-metadata">

**Author:** ![Mind-Brain](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mind-brain/32/906573_2.png) [@Mind-Brain](https://forums.unrealengine.com/u/Mind-Brain)\
**Post date:** [October 11, 2022, 1:51am UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783/2 "2022-10-11T01:51:10Z")

</div>

Hey captain TvZs!

Somebody else had this question and it’s a pretty great solution!

> [@How to get an angle between 2 Vectors?](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850):
>
> Is there a built in function to find the angle between 2 points (2D and 3D) for HUD and World? I love SOH CAH TOA, but l love clean code/blueprints more

---

<div class="post-metadata">

**Author:** ![captainTvZs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/captaintvzs/32/580097_2.png) [@captainTvZs](https://forums.unrealengine.com/u/captainTvZs)\
**Post date:** [October 11, 2022, 2:23am UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783/3 "2022-10-11T02:23:13Z")

</div>

Thank you, but I’m having a little trouble understanding this. Can you sample for me?

---

<div class="post-metadata">

**Author:** ![Chris4K2000](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chris4k2000/32/576471_2.png) [@Chris4K2000](https://forums.unrealengine.com/u/Chris4K2000)\
**Post date:** [October 11, 2022, 5:08am UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783/4 "2022-10-11T05:08:08Z")

</div>

I would create a geometric body used as a collision component for `MyActor` with your desired shape in any 3D software, hide the mesh, enable overlapping events and then trigger an action when the overlap occurrs.

---

<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:** [October 11, 2022, 6:40am UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783/5 "2022-10-11T06:40:27Z")

</div>

The linked thread seems to have everything you need, but here’s a more visual example - perhaps that helps:

> [@How to create God of War targetting system?](https://forums.unrealengine.com/t/how-to-create-god-of-war-targetting-system/210302/2):
>
> [The Dot Product](https://en.wikipedia.org/wiki/Dot_product) of 2 directional vectors will be in range of -1 to 1. Anything that’s above 0 is in front of you, anything below 0 is behind (and every other value in between matters, too!) I grab all the actors around the player using a Sphere Overlap (as in the original suggestion) and loop through the elements of the array, checking my angles - Dot player’s forward and the direction to each target. For dot values greater than .5 I mark the target, and add that actor to the array…

Essentially, you want to use `dot product` and, optionally, convert it to angle. There are more examples linked under the above post.

---

<div class="post-metadata">

**Author:** ![captainTvZs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/captaintvzs/32/580097_2.png) [@captainTvZs](https://forums.unrealengine.com/u/captainTvZs)\
**Post date:** [October 11, 2022, 1:37pm UTC](https://forums.unrealengine.com/t/how-do-i-calculate-when-a-character-is-within-an-angle/666783/6 "2022-10-11T13:37:00Z")

</div>

I’ve thought about it, but the degree I’m stating is constantly changing.
