I'm working on a 2D top down enemy AI. right now i'm just trying to transition the roller ball example to my project so an enemy slime moves and gets to the target. i've tried to adjust the example code to my context, but my agent won't move at all, not even in Heuristic. I have no idea where my mistakes are. Any kind of help is highly appreciated. Here is my Code Code (CSharp): using System.Collections.Generic; using UnityEngine; using Unity.MLAgents; using Unity.MLAgents.Sensors; public class SlimeAgent : Agent { Rigidbody2D rb; public Transform target; public float moveSpeed=10f; void Start() { rb=GetComponent<Rigidbody2D>(); } public override void CollectObservations(VectorSensor sensor) { sensor.AddObservation(target.localPosition); sensor.AddObservation(this.transform.localPosition); } public override void OnActionReceived(float[] vectorAction) { Vector2 movement=Vector2.zero; movement.x=vectorAction[0]; movement.y=vectorAction[1]; rb.MovePosition(rb.position+movement*moveSpeed); } public override void Heuristic(float[] actionsOut) { actionsOut[0] = Input.GetAxisRaw("Horizontal"); actionsOut[1] = Input.GetAxisRaw("Vertical"); } }
Have you verified that your code is being called? You can either do this by connecting a debugger, or using statements like Debug.Log("calling CollectObservations"). If it's not being called, make sure to either call Agent.RequestDecision(), or add a DecisionRequester component to the GameObject. If it is being called, the next step would be to verify whether you're getting non-zero action values.