Download Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/GroundContact.cs from ashish2244/ppo-SnowballTarget: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/ashish2244/ppo-SnowballTarget/resolve/main/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/GroundContact.cs
- Command line
-
hf download hf://ashish2244/ppo-SnowballTarget/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/GroundContact.cs
-
curl -L -o GroundContact.cs https://huggingface.co/ashish2244/ppo-SnowballTarget/resolve/main/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/GroundContact.cs
1.83 kB
| using UnityEngine; | |
| using Unity.MLAgents; | |
| namespace Unity.MLAgentsExamples | |
| { | |
| /// <summary> | |
| /// This class contains logic for locomotion agents with joints which might make contact with the ground. | |
| /// By attaching this as a component to those joints, their contact with the ground can be used as either | |
| /// an observation for that agent, and/or a means of punishing the agent for making undesirable contact. | |
| /// </summary> | |
| [] | |
| public class GroundContact : MonoBehaviour | |
| { | |
| [] public Agent agent; | |
| [] public bool agentDoneOnGroundContact; // Whether to reset agent on ground contact. | |
| public bool penalizeGroundContact; // Whether to penalize on contact. | |
| public float groundContactPenalty; // Penalty amount (ex: -1). | |
| public bool touchingGround; | |
| const string k_Ground = "ground"; // Tag of ground object. | |
| /// <summary> | |
| /// Check for collision with ground, and optionally penalize agent. | |
| /// </summary> | |
| void OnCollisionEnter(Collision col) | |
| { | |
| if (col.transform.CompareTag(k_Ground)) | |
| { | |
| touchingGround = true; | |
| if (penalizeGroundContact) | |
| { | |
| agent.SetReward(groundContactPenalty); | |
| } | |
| if (agentDoneOnGroundContact) | |
| { | |
| agent.EndEpisode(); | |
| } | |
| } | |
| } | |
| /// <summary> | |
| /// Check for end of ground collision and reset flag appropriately. | |
| /// </summary> | |
| void OnCollisionExit(Collision other) | |
| { | |
| if (other.transform.CompareTag(k_Ground)) | |
| { | |
| touchingGround = false; | |
| } | |
| } | |
| } | |
| } | |