# How to Calculate Angle Between Player and Enemy and Check if Within Attack Range

**URL:** <https://forums.unrealengine.com/t/how-to-calculate-angle-between-player-and-enemy-and-check-if-within-attack-range/1887026>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint\
**Created:** [June 3, 2024, 9:59am UTC](https://forums.unrealengine.com/t/how-to-calculate-angle-between-player-and-enemy-and-check-if-within-attack-range/1887026 "2024-06-03T09:59:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [June 3, 2024, 10:12am UTC](https://forums.unrealengine.com/t/how-to-calculate-angle-between-player-and-enemy-and-check-if-within-attack-range/1887026/2 "2024-06-03T10:12:52Z")

</div>

- no need to normalise direction, it’s already normalised
- `Get Unit Direction` can shave nodes off your script
- no need for cross product unless you need left / right
- `Dot` → `aCOSd` is faster; or skip the degrees entirely and work with dot values directly

> [@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…

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-calculate-angle-between-player-and-enemy-and-check-if-within-attack-range/1887026)._
