File size: 1,152 Bytes
05c9ac2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using UnityEngine;
namespace Unity.MLAgentsExamples
{
/// <summary>
/// This class contains logic for locomotion agents with joints which might make contact with a target.
/// By attaching this as a component to those joints, their contact with the ground can be used as
/// an observation for that agent.
/// </summary>
[DisallowMultipleComponent]
public class TargetContact : MonoBehaviour
{
[Header("Detect Targets")] public bool touchingTarget;
const string k_Target = "target"; // Tag on target object.
/// <summary>
/// Check for collision with a target.
/// </summary>
void OnCollisionEnter(Collision col)
{
if (col.transform.CompareTag(k_Target))
{
touchingTarget = true;
}
}
/// <summary>
/// Check for end of ground collision and reset flag appropriately.
/// </summary>
void OnCollisionExit(Collision other)
{
if (other.transform.CompareTag(k_Target))
{
touchingTarget = false;
}
}
}
}
|