ML代理中相机传感器的问题
我正在尝试使用ML代理进行AI,但我似乎无法让相机传感器实际提供输入。我已经遵循了几个教程,但没有一个人足够深入,如果他们做的话,它们已经过时了。这是我的代码:
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using UnityEngine.SceneManagement;
using Unity.MLAgents.Actuators;
public class MyAgent : Agent
{
Rigidbody2D rb2D;
public bool space;
public Vector3 targetPos;
[SerializeField] CameraSensor Observer;
public void Start()
{
rb2D = GetComponent<Rigidbody2D>();
Observer = GetComponent<CameraSensor>();
}
public override void OnActionReceived(ActionBuffers actions)
{
if (actions.DiscreteActions[1] == 1)
{
space = true;
RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2((float)0.1, 1), 100000.0f, 1);
targetPos = hit.point;
}
else
{
space = false;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Obstacles")
{
AddReward(-50f);
EndEpisode();
SceneManager.LoadScene(0);
}
else if (collision.tag == "Checkpoint")
{
AddReward(1f);
}
}
private void FixedUpdate()
{
if (space == true)
{
if (targetPos.x > transform.position.x && rb2D.velocity.x < 20)
{
rb2D.velocity = new Vector2(rb2D.velocity.x + (0.05f * (20 - rb2D.velocity.x)), rb2D.velocity.y);
}
else if (rb2D.velocity.x < -20)
{
rb2D.velocity = new Vector2(rb2D.velocity.x - (0.015f * (20 - rb2D.velocity.x)), rb2D.velocity.y);
}
if (targetPos.y > transform.position.y && rb2D.velocity.y < 20)
{
rb2D.velocity = new Vector2(rb2D.velocity.x, rb2D.velocity.y + (0.025f * (20 - rb2D.velocity.y)));
}
else if (rb2D.velocity.y < -20)
{
rb2D.velocity = new Vector2(rb2D.velocity.x, rb2D.velocity.y - (0.025f * (20 - rb2D.velocity.y)));
}
}
}
}
这是我遇到的错误:
参数exception:getComponent需要请求的组件 “摄影师”源自Monobehaviour或组件,或者是 接口
比矢量观测大小(1)进行的观察值(0)。这 观察将被填充。 UnityEngine.debug:logwarningformat (String,Object [])unity.mlagents.sensors.vectorsensor:写入 (unity.mlagents.sensors.observationwriter)(at 库/packagecache/
我不确定这是由我在代码中缺少的东西还是我缺少的组件或类似的内容引起的。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论