Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

47 行
1.5 KiB

using UnityEngine;
using UnityEngine.Serialization;
namespace Unity.MLAgents.Sensors
{
public class CustomRayPerceptionOutput : RayPerceptionOutput
{
public CustomRayPerceptionOutput()
{
CustomObservationSizePerRay = 3;
}
public override void GetCustomObservationData(RayOutput rayOutput, float[] buffer)
{
var rb = rayOutput.HitGameObject.GetComponent<Rigidbody>();
if (rb != null)
{
buffer[0] = rb.velocity.x;
buffer[1] = rb.velocity.z;
buffer[2] = rb.mass;
}
}
}
/// <summary>
/// A component for Custom 3D Ray Perception.
/// </summary>
[AddComponentMenu("ML Agents/Custom Ray Perception Sensor 3D", (int)MenuGroup.Sensors)]
public class RayPerceptionSensorComponentCustom3D : RayPerceptionSensorComponent3D
{
public override ISensor[] CreateSensors()
{
var rayPerceptionInput = GetRayPerceptionInput();
var rayPerceptionOutput = new CustomRayPerceptionOutput();
m_RaySensor = new RayPerceptionSensor(SensorName, rayPerceptionInput, rayPerceptionOutput);
if (ObservationStacks != 1)
{
var stackingSensor = new StackingSensor(m_RaySensor, ObservationStacks);
return new ISensor[] { stackingSensor };
}
return new ISensor[] { m_RaySensor };
}
}
}