@@ -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