# Ray cast Observation for obstacles detection and Rewards

**URL:** <https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Learning-Agents, question\
**Created:** [May 2, 2024, 2:27pm UTC](https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583 "2024-05-02T14:27:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahzad](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mahzad/32/745429_2.png) [@Mahzad](https://forums.unrealengine.com/u/Mahzad)\
**Post date:** [May 2, 2024, 2:27pm UTC](https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583/1 "2024-05-02T14:27:36Z")

</div>

Hello everyone,  
I’m looking for feedbacks on people who have used ray cast in observations, especially to detect obstacles.  
How do you manage rewards based on raycasts?

We can add rewards based on hit functions, but in this case we don’t really need ray casts.

Any feedback is welcome 🙂  
Thanks

---

<div class="post-metadata">

**Author:** ![Delladep](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Delladep](https://forums.unrealengine.com/u/Delladep)\
**Post date:** [May 2, 2024, 3:59pm UTC](https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583/2 "2024-05-02T15:59:24Z")

</div>

This could be useful: [https://forums.unrealengine.com/t/what-is-the-best-way-to-add-ray-cast-to-observations-learning-agents-5-4/1817197](https://forums.unrealengine.com/t/what-is-the-best-way-to-add-ray-cast-to-observations-learning-agents-5-4/1817197)

---

<div class="post-metadata">

**Author:** ![Mahzad](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mahzad/32/745429_2.png) [@Mahzad](https://forums.unrealengine.com/u/Mahzad)\
**Post date:** [May 2, 2024, 4:01pm UTC](https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583/3 "2024-05-02T16:01:57Z")

</div>

Thanks, the point is not how to add raycast on the observation, but if is it still need to add on the agent a Hit event

---

<div class="post-metadata">

**Author:** ![Delladep](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Delladep](https://forums.unrealengine.com/u/Delladep)\
**Post date:** [May 3, 2024, 9:24am UTC](https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583/4 "2024-05-03T09:24:42Z")

</div>

You can get the collision distance from the Line Trace raycast and then create a reward based on, for example, either the collision distance of the shortest ray or the mean of the distances. I’m not sure if that was the question.
