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

39 行
1.0 KiB

using UnityEngine;
public class TennisArea : MonoBehaviour
{
public GameObject ball;
public GameObject agentA;
public GameObject agentB;
Rigidbody m_BallRb;
// Use this for initialization
void Start()
{
m_BallRb = ball.GetComponent<Rigidbody>();
MatchReset();
}
public void MatchReset()
{
var ballOut = Random.Range(6f, 8f);
var flip = Random.Range(0, 2);
if (flip == 0)
{
ball.transform.position = new Vector3(-ballOut, 6f, 0f) + transform.position;
}
else
{
ball.transform.position = new Vector3(ballOut, 6f, 0f) + transform.position;
}
m_BallRb.velocity = new Vector3(0f, 0f, 0f);
ball.transform.localScale = new Vector3(1, 1, 1);
ball.GetComponent<HitWall>().lastAgentHit = -1;
}
void FixedUpdate()
{
var rgV = m_BallRb.velocity;
m_BallRb.velocity = new Vector3(Mathf.Clamp(rgV.x, -9f, 9f), Mathf.Clamp(rgV.y, -9f, 9f), rgV.z);
}
}