# Learning Agents Project Doesn't Work as Expected

**URL:** <https://forums.unrealengine.com/t/learning-agents-project-doesnt-work-as-expected/2352999>\
**Category:** Blueprint\
**Tags:** Reinforcement-Learning, unreal-engine, Machine-Learning, Learning-Agents, question\
**Created:** [February 23, 2025, 6:50pm UTC](https://forums.unrealengine.com/t/learning-agents-project-doesnt-work-as-expected/2352999 "2025-02-23T18:50:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enesQwerty3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/enesqwerty3/32/1031992_2.png) [@enesQwerty3](https://forums.unrealengine.com/u/enesQwerty3)\
**Post date:** [February 23, 2025, 6:50pm UTC](https://forums.unrealengine.com/t/learning-agents-project-doesnt-work-as-expected/2352999/1 "2025-02-23T18:50:35Z")

</div>

Hi, I’m working on a Learning Agents project in Unreal Engine 5.4 as my graduation project but I have a problem and I don’t know where I’m doing mistake. I need your help guys. I have to finish this project as soon as possible.

**Case**

> There is an agent and my goal is make agent to follow the player until distance between agent and player is 2 meter. And rotate agent’s direction towards the player.

**Problem**

> Rotating work fine after training for 15 mins but movement doesn’t work well even for 2 hours training.

**Specify Agent Observation**

1-Specify agent location and direction observation.

 ![specify agent observation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/2/7e2d9cab324455b793ed7f89d0cdf72e0d57edc6.png)

2-Specify player location and direction observation.

 ![specify player observation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/d/08d486dd7aece3403bfdeb88f9027c3f6f6bc57c.png)

**Gather Agent Observation**

1-Gather agent location and direction observation

 ![gather agent observation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/e/1eecf899a32b03004728abe32b83c45eb786732a.png)

2- Gather player location and direction observation

 ![gather player observation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/d/6/6d65b03327ab459a40ba61e25ee92e42bc9868b8.png)

This _Player Pos_ and _Player Direction_ (which is normalized player location - agent location vector) values are updating in agent’s tick function.

**Specify Agent Action**

These are the specified agent actions.

 ![specify agent action](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/a/2/ca20df94a6a3aaafcfd6c7b279c83fec55e4caf8.png)

**Perform Agent Action**

This how I perform action values.

1-Direction

 ![perform agent action - direction](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/4/3b46a6e7cdb64d47802a748c942fbec922554c64.png)

2-Movement

 ![perform agent action - movement](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/f/42feca1a340dadd9aea17b53b4eee65e9e8f7587.png)

**Gather Agent Reward**

1- Direction reward

 ![direction reward](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/9/c7910bcc582aa4b0d68199156539d3bccdc11dff.png)

2-Movement reward  
These bool variables are updating in agents tick function to determine if agent moving towards player or away from player.

 ![movement reward](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/e/a1e46b19ccb04de67264db9d49d9bdbd7911c6e0.png)

**Agent Tick Function**

 ![agent tick 1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/0/6b0b79763d215ee094ee53e33c1adec96d34a3f7.png)

 ![agent tick 2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/d/a2da4e206db165b2068d049b5bd9bfb3ca241ec8.png)

Beside this movement rewards I’ve tried _make reward on location difference above threshold_ and _make reward on location similarity_ functions separately but both didn’t work as expected. Even after 2 hours of training when I run inference agents were moving off from player to a no sense direction.

---

<div class="post-metadata">

**Author:** ![enesQwerty3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/enesqwerty3/32/1031992_2.png) [@enesQwerty3](https://forums.unrealengine.com/u/enesQwerty3)\
**Post date:** [February 26, 2025, 4:42pm UTC](https://forums.unrealengine.com/t/learning-agents-project-doesnt-work-as-expected/2352999/2 "2025-02-26T16:42:47Z")

</div>

In perform agent action instead of using XInput and YInput float values to make a direction vector used them in _AddMovementInput_ function. **XInput** to scale forward movement and **YInput** to scale right movement.

 ![solution 1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/d/82dafb68a1c7a0cbf795c13aa936bf7f695680ce.png)

And I updated my reward functions. There is no need to calculate movement direction inside tick function. I assume default location based reward functions (like make reward from location similarity) better than mine.

 ![reward 1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/e/3/ee3bb9bc8e89242dc6cc9f84adb6544cb6e1f63d.png)

 ![reward 2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/3/e037073eacae5391002abb009c31b3847fef849b.png)

This is the result of approximately 1 hour of training.

---

<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:** [March 28, 2025, 4:43pm UTC](https://forums.unrealengine.com/t/learning-agents-project-doesnt-work-as-expected/2352999/3 "2025-03-28T16:43:45Z")

</div>

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