浏览代码

Fix vertical offsets for RayPerception3D (#2823)

* clean up ray perception

* adjust offsets

* remove dead code
/develop-newnormalization
GitHub 5 年前
当前提交
6f921ec5
共有 4 个文件被更改,包括 13 次插入12 次删除
  1. 2
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
  2. 19
      UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs
  3. 2
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  4. 2
      UnitySDK/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs

2
UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs


var rayDistance = 12f;
AddVectorObs(m_RayPer.Perceive(rayDistance, m_RayAngles, m_DetectableObjects));
AddVectorObs(m_RayPer.Perceive(rayDistance, m_RayAngles, m_DetectableObjects, 1.5f));
AddVectorObs(m_RayPer.Perceive(rayDistance, m_RayAngles, m_DetectableObjects, 1.5f, 1.5f));
}
}

19
UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs


/// </summary>
public class RayPerception3D : RayPerception
{
Vector3 m_EndPosition;
RaycastHit m_Hit;
float[] m_SubList;

// along with object distance.
foreach (var angle in rayAngles)
{
m_EndPosition = transform.TransformDirection(
PolarToCartesian(rayDistance, angle));
m_EndPosition.y = endOffset;
Vector3 startPositionLocal = new Vector3(0, startOffset, 0);
Vector3 endPositionLocal = PolarToCartesian(rayDistance, angle);
endPositionLocal.y += endOffset;
var startPositionWorld = transform.TransformPoint(startPositionLocal);
var endPositionWorld = transform.TransformPoint(endPositionLocal);
var rayDirection = endPositionWorld - startPositionWorld;
Debug.DrawRay(transform.position + new Vector3(0f, startOffset, 0f),
m_EndPosition, Color.black, 0.01f, true);
Debug.DrawRay(startPositionWorld,rayDirection, Color.black, 0.01f, true);
if (Physics.SphereCast(transform.position +
new Vector3(0f, startOffset, 0f), 0.5f,
m_EndPosition, out m_Hit, rayDistance))
if (Physics.SphereCast(startPositionWorld, 0.5f, rayDirection, out m_Hit, rayDistance))
{
for (var i = 0; i < detectableObjects.Length; i++)
{

2
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


detectableObjects = m_DetectableObjectsBlue;
}
AddVectorObs(m_RayPer.Perceive(rayDistance, m_RayAngles, detectableObjects));
AddVectorObs(m_RayPer.Perceive(rayDistance, m_RayAngles, detectableObjects, 1f));
AddVectorObs(m_RayPer.Perceive(rayDistance, m_RayAngles, detectableObjects, 1f, 1f));
}
public void MoveAgent(float[] act)

2
UnitySDK/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs


AddVectorObs(m_RayPer.Perceive(
rayDistance, rayAngles, m_DetectableObjects));
AddVectorObs(m_RayPer.Perceive(
rayDistance, rayAngles, m_DetectableObjects, 2.5f, 2.5f));
rayDistance, rayAngles, m_DetectableObjects, 2.5f, 5.0f));
var agentPos = m_AgentRb.position - ground.transform.position;
AddVectorObs(agentPos / 20f);

正在加载...
取消
保存