implementation of drecon in unity 2022 lts forked from: https://github.com/joanllobera/marathon-envs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

9 months ago
using UnityEngine;
namespace Unity.MLAgents
{
public class SensorBehavior : MonoBehaviour
{
MarathonAgent _marathonAgent;
IOnSensorCollision _onSensorCollision;
Collider _collider;
void Start()
{
_marathonAgent = GetComponentInParent<MarathonAgent>();
_onSensorCollision = GetComponentInParent<IOnSensorCollision>();
_collider = GetComponent<Collider>();
}
void OnCollisionEnter(Collision other)
{
if (_marathonAgent != null)
_marathonAgent.SensorCollisionEnter(_collider, other);
if (_onSensorCollision != null)
{
9 months ago
_onSensorCollision.OnSensorCollisionEnter(_collider, other.gameObject);
}
9 months ago
}
void OnCollisionExit(Collision other)
{
if (_marathonAgent != null)
_marathonAgent.SensorCollisionExit(_collider, other);
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionExit(_collider, other.gameObject);
}
void OnTriggerEnter(Collider other)
{
if (_onSensorCollision != null)
{
9 months ago
_onSensorCollision.OnSensorCollisionEnter(_collider, other.gameObject);
}
9 months ago
}
void OnTriggerExit(Collider other)
{
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionExit(_collider, other.gameObject);
}
void OnTriggerStay(Collider other)
{
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionEnter(_collider, other.gameObject);
}
void FootCheck(Collision sensor)
{
Debug.Log($"{sensor}");
if (sensor.gameObject.name == "right_foot_heal_senor_l" || sensor.gameObject.name == "left_foot_heal_senor_l")
{
float collision = sensor.relativeVelocity.magnitude;
Debug.Log($"{collision}");
}
}
9 months ago
}
}