Reputation: 13
I am trying to override the OnActionReceived
method of the Agent
class. But I don't think that the function is getting called and it doesn't give me any error.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class MoveCar : Agent
{
// more code here
public override void OnActionReceived(ActionBuffers actions)
{
// Get the acceleration, brake, and steer actions from the ML-Agents system
float acceleration = actions.ContinuousActions[0];
float brake = Mathf.Clamp(actions.ContinuousActions[1], 0, 1);
float steer = actions.ContinuousActions[2];
Debug.Log(acceleration);
nowAcceleration = motorMax * acceleration;
nowBrake = brakeMax * brake;
nowSteer = steerMax * steer;
// Apply the actions to the car
wheelBackLeft.motorTorque = nowAcceleration;
wheelBackRight.motorTorque = nowAcceleration;
wheelBackLeft.brakeTorque = nowBrake;
wheelBackRight.brakeTorque = nowBrake;
// wheelFrontLeft.brakeTorque = nowBrake;
// wheelFrontRight.brakeTorque = nowBrake;
wheelFrontLeft.steerAngle = nowSteer;
wheelFrontRight.steerAngle = nowSteer;
updateWheel(wheelFrontLeft, frontLeftTransform);
updateWheel(wheelFrontRight, frontRightTransform);
updateWheel(wheelBackLeft, backLeftTransform);
updateWheel(wheelBackRight, backRightTransform);
}
// more code here
}
I wanted the car to move and to see my acceleration in the Unity3d console but the car does nothing and nothing is printed in the console.
Upvotes: 1
Views: 480