# How to make minimal firing range for units in a game?

**URL:** <https://forums.unrealengine.com/t/how-to-make-minimal-firing-range-for-units-in-a-game/1734272>\
**Category:** Blueprint\
**Tags:** unreal-engine, question\
**Created:** [March 6, 2024, 5:39pm UTC](https://forums.unrealengine.com/t/how-to-make-minimal-firing-range-for-units-in-a-game/1734272 "2024-03-06T17:39:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![theDoron11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theDoron11](https://forums.unrealengine.com/u/theDoron11)\
**Post date:** [March 6, 2024, 5:39pm UTC](https://forums.unrealengine.com/t/how-to-make-minimal-firing-range-for-units-in-a-game/1734272/1 "2024-03-06T17:39:13Z")

</div>

Hi, I am making a strategy game and there are soldiers in a trench. I want them to be able to throw a grenade (I implemented this), but I don’t want them to be able to throw it too close to their trench.

I thought about measuring the distance between the thrower and the target. The problem is the trench is wide, so if an enemy is to the other side of the trench the distance will be far enough to throw, even though he is too close to the trench.

Basically, I want to draw a line in the map, or define zones in the map, that are flagged somehow. And the add in my grenade throw logic, a branch where I check if the targeted part of the map is flagged or not.

How do i implement this?

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [March 6, 2024, 6:21pm UTC](https://forums.unrealengine.com/t/how-to-make-minimal-firing-range-for-units-in-a-game/1734272/2 "2024-03-06T18:21:22Z")

</div>

If your map is made of squares, you could build trenches taking [a square of space on a map](https://forums.unrealengine.com/t/projectile-trajectory-and-ground-level/674611/21). Similar to a chess board you then can compare square coordinate of the soldier to square coordinate of the trench (say X3, Y7 is a place on the map marked trench.). In this case I’d have a spawner / subsystem keeping track of what is spawned and where, mapped to those coordinates on a property.

You could also add overlapping collision box to the trench actor, so that when soldiers walk into the invisible box (overlap) they are notified that they can not throw a grenade.

Other option is to measure distance between two locations. You could set Z on the location vectors to 0 to measure only horizontal distance:

```auto
const FVector LocationSub = FVector(133.f, 155.f, 20.f) - FVector(33.f, 75.f, 10.f);
const float Distance = LocationSub.Length();

```

---

<div class="post-metadata">

**Author:** ![theDoron11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theDoron11](https://forums.unrealengine.com/u/theDoron11)\
**Post date:** [March 6, 2024, 7:42pm UTC](https://forums.unrealengine.com/t/how-to-make-minimal-firing-range-for-units-in-a-game/1734272/3 "2024-03-06T19:42:00Z")

</div>

I used the collision box option and it works perfectly and was easy to implement. Thanks a lot for a great answer!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [April 5, 2024, 7:42pm UTC](https://forums.unrealengine.com/t/how-to-make-minimal-firing-range-for-units-in-a-game/1734272/4 "2024-04-05T19:42:21Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
