Hi, I’m having trouble setting up the OnActionReceived() function for mlagents, I’m using the Realistic Car Controller V3 from the asset store. I created a race track and everything works perfectly, other than random behaviour from the car agent. Can anyone please give me some insight on how I should do this? All help is much appreciated.
public override void OnActionReceived(float[] vectorAction)
{
controller.gasInput = Mathf.Clamp(vectorAction[0], 0, 1f);
controller.brakeInput = Mathf.Clamp(vectorAction[1], 0, 1f);
controller.steerInput = Mathf.Clamp(vectorAction[2], -1f ,1f);
}
Gas input is for accelerating, values are 0-1 in the controller script.
Brake input is for braking, values are 0-1 in the controller script.
Steer input is for steering, values are -1 to 1 in the controller script.
These are normally managed with the GetAxis horizontal and vertical, as seen in the heuristic method:
public override void Heuristic(float[] actionsOut)
{
actionsOut[0] = 0;
actionsOut[1] = 0;
actionsOut[2] = 0;
actionsOut[3] = 0;
if (Input.GetAxis("Vertical") == 1)
{
//Accelerating
actionsOut[0] = 1;
}
else if(Input.GetAxis("Vertical") == -1)
{
//Braking
actionsOut[1] = 1;
}
else if (Input.GetAxis("Horizontal") == 1)
{
//Steer Right
actionsOut[2] = 1;
}
else if(Input.GetAxis("Horizontal") == -1)
{
//Steer Left
actionsOut[3] = 1;
}
}
I will accept all criticism as I’m very new in ml-agents and thank you for all comments.