# Learning Agents Driving Tutorial + Obstacle avoidance

**URL:** <https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470>\
**Category:** Blueprint\
**Tags:** Reinforcement-Learning, unreal-engine, Learning-Agents, question\
**Created:** [December 27, 2024, 12:54pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470 "2024-12-27T12:54:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OptimusSkooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OptimusSkooch](https://forums.unrealengine.com/u/OptimusSkooch)\
**Post date:** [December 27, 2024, 12:54pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/1 "2024-12-27T12:54:50Z")

</div>

Hi

I’m trying to make the driving agents also avoid obstacles on the track, but I can’t get it to work. After reading all the posts about this topic, such as: [Learning Agents 5.4 Question, adding obstacles to the track of the tutorial](https://forums.unrealengine.com/t/learning-agents-5-4-question-adding-obstacles-to-the-track-of-the-tutorial/1833240), [What is the best way to add ray cast to observations? Learning Agents 5.4](https://forums.unrealengine.com/t/what-is-the-best-way-to-add-ray-cast-to-observations-learning-agents-5-4/1817197) and [Ray cast Observation for obstacles detection and Rewards](https://forums.unrealengine.com/t/ray-cast-observation-for-obstacles-detection-and-rewards/1836583/3), my implementation looks like this:

**Interactor**

1. Specify Agent Observation  

2. Gather Agent Observation  

I basically shoot 7 rays, _make array_ represents the angles.

1. Actions  
I didn’t change the actions.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/6/f/f6ff9b51e7267a4d4f369d0b424028cfeb8a9816.png)

**Trainer**

1. Gather Agent Reward  
I still want the car to drive forward, so I let the following rewards from the tutorial in there:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/d/3/3d3dd3bbc81d06cf81ffccc92f6faf83734ba2c1.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/d/60d826403572bfc0067294b43c0f723859817a59.png)n

And those are the rewards I added:  
First I raycast 3 times:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/6/b56aaa0d758e45d67ceaac3a716421f933c3599e.png)  
Then I give a penalty if the actor gets too close to the Hit positions of the obstacles  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/b/98ba46a8e9d83db9c8adaf5780011c04f7afa0dc.png)

If the car actually hits something (OnActorBeginOverlap), I also give a penalty:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/3/5/d354855e4dbc952ca82687162bf6ad69cd660a09.png)

I’ve experimented with different _Distance Thresholds_ and _Reward Scales_, but at the end they drive as fast as they can without accounting for any obstacles.

1. Gather Agent Completion  
If they drive out of the track:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/f/6/ff6734e691810e5e505071e387aeadadd3bfa1f1.png)  
If they hit something, or are about to hit something  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/8/ab88a1c712723cf4763c16e70e7cfcbc061e1648.png)

Then I add those together with _Or_ node

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/9/3/593f0ad018334667d7b808d1b614653a9777ab08.png)

This is the track, the white dots are the obstacles:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/9/1a9221597e3a3affe761168eee14b42464753737.png)

I let this run overnight, and the result was them just hitting any obstacle on the path, not even trying to avoid. Any idea what I’m doing wrong? Any help is appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![AlexarassK](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexarassK](https://forums.unrealengine.com/u/AlexarassK)\
**Post date:** [December 29, 2024, 10:06pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/2 "2024-12-29T22:06:13Z")

</div>

Maybe you’ve already checked but make sure that the basics are all working. Check that your obstacles have query collisions enabled. If they do, make sure that your collisions are hitting etc.

I am seeing something odd though. After making sure of the above and anything else you might have missed or assumed to be a fact without checking, do check that “Make proportion along ray observation” node. I have a suspicion that if you debug draw the line trace it won’t be correct. I think this function expects a local start and local finish not a world. The reason I think that is because it’s taking in a transform. Try placing the start at 0,0,0 and the end at your mesh’s forward vector multiplied by the length of your car’s vision.

---

<div class="post-metadata">

**Author:** ![OptimusSkooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OptimusSkooch](https://forums.unrealengine.com/u/OptimusSkooch)\
**Post date:** [December 30, 2024, 12:31pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/3 "2024-12-30T12:31:26Z")

</div>

Thank you for your reply @AlexarassK. Make Proportion Along Ray Observation was indeed the problem. The rays were being debug drawn at wrong locations.  
This solved it:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/e/abeb3763a838ef6fdcc5f8430809df058c291f16.png)

Thank you so much!

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [January 6, 2025, 8:53pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/4 "2025-01-06T20:53:32Z")

</div>

Awesome. You don’t know how happy it makes me to see people helping each other in the community with this. I never wanted to be the bottleneck so kudos to you both for helping each other. Thanks!

---

<div class="post-metadata">

**Author:** ![OptimusSkooch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OptimusSkooch](https://forums.unrealengine.com/u/OptimusSkooch)\
**Post date:** [January 26, 2025, 3:15pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/5 "2025-01-26T15:15:05Z")

</div>

Thanks a lot for the awesome plugin. Did my graduation work using Learning Agents, and it was a ton of fun!

For anyone interested: [https://github.com/hovo-hakobyan/Autonomous-Driving-Learning-Agents-5.4](https://github.com/hovo-hakobyan/Autonomous-Driving-Learning-Agents-5.4)

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [January 27, 2025, 2:48pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/6 "2025-01-27T14:48:59Z")

</div>

Awesome work! Just gave it a quick skim and looks interesting - will have to take a deeper look soon. Thanks for sharing!

---

<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:** [February 26, 2025, 2:49pm UTC](https://forums.unrealengine.com/t/learning-agents-driving-tutorial-obstacle-avoidance/2245470/7 "2025-02-26T14:49:27Z")

</div>

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