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

67 行
2.0 KiB

//Put this script on your blue cube.
using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using Unity.MLAgentsExamples;
public class WallJumpCollabAgent : WallJumpAgent
{
Vector3 m_InitialPosition;
WallAreaScoring m_Scoring;
public override void Initialize()
{
m_WallJumpSettings = FindObjectOfType<WallJumpSettings>();
m_Scoring = ground.GetComponent<WallAreaScoring>();
m_Configuration = 5;
m_AgentRb = GetComponent<Rigidbody>();
// m_ShortBlockRb = shortBlock.GetComponent<Rigidbody>();
m_SpawnAreaBounds = spawnArea.GetComponent<Collider>().bounds;
m_GroundRenderer = ground.GetComponent<Renderer>();
m_GroundMaterial = m_GroundRenderer.material;
m_InitialPosition = transform.localPosition;
spawnArea.SetActive(false);
m_ResetParams = Academy.Instance.EnvironmentParameters;
}
public override void OnEpisodeBegin()
{
transform.localPosition = m_InitialPosition;
m_Configuration = 5;
m_AgentRb.velocity = default(Vector3);
}
public override void OnActionReceived(ActionBuffers actionBuffers)
{
MoveAgent(actionBuffers.DiscreteActions);
if (!Physics.Raycast(m_AgentRb.position, Vector3.down, 20))
{
m_Scoring.LoseCondition();
}
}
protected override void ConfigureAgent(int config)
{
var localScale = wall.transform.localScale;
var height = m_ResetParams.GetWithDefault("big_wall_height", 9);
localScale = new Vector3(
localScale.x,
height,
localScale.z);
wall.transform.localScale = localScale;
}
// Detect when the agent hits the goal
protected override void OnTriggerStay(Collider col)
{
if (col.gameObject.CompareTag("goal") && DoGroundCheck(true))
{
m_Scoring.WinCondition();
}
}
}