# Change actor location randomly within box

**URL:** <https://forums.unrealengine.com/t/change-actor-location-randomly-within-box/438348>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 26, 2018, 4:33pm UTC](https://forums.unrealengine.com/t/change-actor-location-randomly-within-box/438348 "2018-11-26T16:33:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7011f300](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7011f300](https://forums.unrealengine.com/u/anonymous_user_7011f300)\
**Post date:** [November 26, 2018, 4:33pm UTC](https://forums.unrealengine.com/t/change-actor-location-randomly-within-box/438348/1 "2018-11-26T16:33:23Z")

</div>

I am trying to make a coin (just a black cylinder) disappear, change to a new random location within a specific area, and reappear every time I press the right mouse button. My level blueprint successfully makes the coin disappear, change location, and reappear when I click the right mouse key, but it often appears at locations outside of my quadrant 1 box that I want it to stay within. Does anyone know what I might have done wrong in my code to allow the coin to appear anywhere outside of the box that I want it to stay within?

 ![260481-randomfloatbp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/4/c/a4c484360da5027eaf6f67f8c7cf247c562fab73.png)

 ![260482-levelimage.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/5/a/85ad85327c1baf87291d79bce99fc60b4e2df15c.jpeg)

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [November 26, 2018, 5:30pm UTC](https://forums.unrealengine.com/t/change-actor-location-randomly-within-box/438348/2 "2018-11-26T17:30:39Z")

</div>

You are adding the random numbers to your actor’s world location, but you have to add those random numbers to the quadrant origin. Your new location mustn’t depend on your previous location, but only on the quadrant’s origin and bounds. Something like this:

 ![260478-spawn.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/7/8/d788837a181fa2822f3666e096b49f3f32921414.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7011f300](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7011f300](https://forums.unrealengine.com/u/anonymous_user_7011f300)\
**Post date:** [November 27, 2018, 4:38pm UTC](https://forums.unrealengine.com/t/change-actor-location-randomly-within-box/438348/3 "2018-11-27T16:38:52Z")

</div>

Ah, I see. That did the trick perfectly! Thank you!

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [November 27, 2018, 4:51pm UTC](https://forums.unrealengine.com/t/change-actor-location-randomly-within-box/438348/4 "2018-11-27T16:51:28Z")

</div>

Glad I could be of help!
