using UnityEngine;
namespace MLAgents
{
///
/// 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.
///
[DisallowMultipleComponent]
public class TargetContact : MonoBehaviour
{
[Header("Detect Targets")] public bool touchingTarget;
private const string k_Target = "target"; // Tag on target object.
///
/// Check for collision with a target.
///
void OnCollisionEnter(Collision col)
{
if (col.transform.CompareTag(k_Target))
{
touchingTarget = true;
}
}
///
/// Check for end of ground collision and reset flag appropriately.
///
void OnCollisionExit(Collision other)
{
if (other.transform.CompareTag(k_Target))
{
touchingTarget = false;
}
}
}
}