Skip to content

Commit 4484dc7

Browse files
authored
Merge pull request #2457 from Unity-Technologies/hh/fix-training-NaN-errors-crawler
Fix NaN training errors for crawler
2 parents f67196c + 74aa386 commit 4484dc7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public override void InitializeAgent()
5454
{
5555
jdController = GetComponent<JointDriveController>();
5656
currentDecisionStep = 1;
57+
dirToTarget = target.position - body.position;
58+
5759

5860
//Setup each body part
5961
jdController.SetupBodyPart(body);
@@ -113,12 +115,12 @@ public void CollectObservationBodyPart(BodyPart bp)
113115
public override void CollectObservations()
114116
{
115117
jdController.GetCurrentJointForces();
116-
// Normalize dir vector to help generalize
117118

119+
// Update pos to target
120+
dirToTarget = target.position - body.position;
118121
lookRotation = Quaternion.LookRotation(dirToTarget);
119122
targetDirMatrix = Matrix4x4.TRS(Vector3.zero, lookRotation, Vector3.one);
120123

121-
// Forward & up to help with orientation
122124
RaycastHit hit;
123125
if (Physics.Raycast(body.position, Vector3.down, out hit, 10.0f))
124126
{
@@ -127,6 +129,7 @@ public override void CollectObservations()
127129
else
128130
AddVectorObs(10.0f);
129131

132+
// Forward & up to help with orientation
130133
Vector3 bodyForwardRelativeToLookRotationToTarget = targetDirMatrix.inverse.MultiplyVector(body.forward);
131134
AddVectorObs(bodyForwardRelativeToLookRotationToTarget);
132135

@@ -174,9 +177,6 @@ public override void AgentAction(float[] vectorAction, string textAction)
174177
}
175178
}
176179

177-
// Update pos to target
178-
dirToTarget = target.position - jdController.bodyPartsDict[body].rb.position;
179-
180180
// If enabled the feet will light up green when the foot is grounded.
181181
// This is just a visualization and isn't necessary for function
182182
if (useFootGroundedVisualization)

0 commit comments

Comments
 (0)