Я просмотрел учебник по агентам ОД. Я почти ничего не менял в коде, кроме функции OnEpisodeBegin, где заменил Vector3.zero; со стартовой позицией моего агента.
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class MoveAgent : Agent
{
[SerializeField]
private Transform targetTransform;
public override void OnEpisodeBegin(){
transform.position = new Vector3(42.59956f, 18.9153f, 144.7489f);
}
public override void CollectObservations(VectorSensor sensor){
sensor.AddObservation(transform.position);
sensor.AddObservation(targetTransform.position);
}
public override void OnActionReceived(ActionBuffers actions){
float moveX = actions.ContinuousActions[0];
float moveZ = actions.ContinuousActions[1];
float moveSpeed = 2f;
transform.localPosition += new Vector3(moveX, 0, moveZ) * Time.deltaTime * moveSpeed;
}
public override void Heuristic(in ActionBuffers actionsOut){
ActionSegment continuousActions = actionsOut.ContinuousActions;
continuousActions[0] = Input.GetAxisRaw("Horizontal");
continuousActions[1] = Input.GetAxisRaw("Vertical");
}
private void OnTriggerEnter(Collider other){
if (other.TryGetComponent(out Goal goal)){
SetReward(+1f);
EndEpisode();
}
if (other.TryGetComponent(out Wall wall)){
SetReward(-1f);
EndEpisode();
}
}
}
`
What could the problem be?
Подробнее здесь: https://stackoverflow.com/questions/738 ... is-touched
Эпизод Unity не заканчивается, даже если цель или стена затронуты ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение