- Create an class for your agent extending
Agent
, and implement the follow methods:
protected override void ExecuteAction(int action)
{
switch (action)
{
case 0: _dir = Vector2.left; break;
case 1: _dir = Vector2.up; break;
case 2: _dir = Vector2.right; break;
case 3: _dir = Vector2.down; break;
case 4: _dir = Vector2.left + Vector2.up; break;
case 5: _dir = Vector2.right + Vector2.up; break;
case 6: _dir = Vector2.left + Vector2.down; break;
case 7: _dir = Vector2.right + Vector2.down; break;
}
}
protected override float GetReward()
{
var reward = 1f - _endDistance / 3f;
if (_endDistance <= 1.5f) return reward * 2f;
if (_endDistance > _initialDistance) return -1f;
return reward;
}
protected override float[] GetState()
{
var direction = (transform.position - target.position).normalized;
return new float[] { direction.x, direction.y };
}
- Create a Brain ScriptableObject and attach in you agent
- Ajdust params and train
- Traning - First epochs
2024-04-24.09-12-58.mp4
- Training - Last epochs
2024-04-24.09-06-57.mp4
- Final Result