浏览代码

faster ball

/asymm-envs
Andrew Cohen 5 年前
当前提交
c702bb27
共有 2 个文件被更改,包括 1 次插入12 次删除
  1. 11
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  2. 2
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs

11
Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs


public GameObject myArea;
public float scale;
[HideInInspector]
// accumulator of energy penalty
public float energyPenalty = 0;
Text m_TextComponent;
Rigidbody m_AgentRb;
Rigidbody m_BallRb;

float m_InvertMult;
FloatPropertiesChannel m_ResetParams;
float m_BallTouch;
Vector3 down = new Vector3(0f, -100f, 0f);
Vector3 zAxis = new Vector3(0f, 0f, 1f);
const float k_Angle = 90f;

var rotateZ = angle - (gameObject.transform.rotation.eulerAngles.z - (1f - m_InvertMult) * 180f);
Quaternion deltaRotation = Quaternion.Euler(zAxis * rotateZ * .5f);
m_AgentRb.MoveRotation(m_AgentRb.rotation * deltaRotation);
//gameObject.transform.Rotate(0f, 0f, rotateZ);
if (invertX && transform.position.x - transform.parent.transform.position.x < -m_InvertMult ||
!invertX && transform.position.x - transform.parent.transform.position.x > -m_InvertMult)

}
var rgV = m_AgentRb.velocity;
m_AgentRb.velocity = new Vector3(Mathf.Clamp(rgV.x, -20, 20), Mathf.Min(rgV.y, 10f), rgV.z);
// energy usage penalty cumulant
energyPenalty += -0.001f * (Mathf.Abs(moveX) + upward);
m_TextComponent.text = score.ToString();
}

public override void OnEpisodeBegin()
{
energyPenalty = 0;
m_BallTouch = SideChannelUtils.GetSideChannel<FloatPropertiesChannel>().GetPropertyWithDefault("ball_touch", 0);
m_InvertMult = invertX ? -1f : 1f;
var agentOutX = Random.Range(12f, 16f);
var agentOutY = Random.Range(-1.5f, 0f);

2
Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs


{
m_BallRb.AddForce(down);
var rgV = m_BallRb.velocity;
m_BallRb.velocity = new Vector3(Mathf.Clamp(rgV.x, -30f, 30f), Mathf.Min(rgV.y, 45f), rgV.z);
m_BallRb.velocity = new Vector3(Mathf.Clamp(rgV.x, -40f, 40f), Mathf.Min(rgV.y, 45f), rgV.z);
}
}
正在加载...
取消
保存