|
|
|
|
|
|
public Material groundedMaterial; |
|
|
|
public Material unGroundedMaterial; |
|
|
|
|
|
|
|
Vector3 m_DirToTarget; |
|
|
|
|
|
|
|
m_DirToTarget = target.transform.position - body.position; |
|
|
|
m_JdController = GetComponent<JointDriveController>(); |
|
|
|
|
|
|
|
//Setup each body part
|
|
|
|
|
|
|
{ |
|
|
|
bodyPart.Reset(bodyPart); |
|
|
|
} |
|
|
|
if (m_DirToTarget != Vector3.zero) |
|
|
|
{ |
|
|
|
transform.rotation = Quaternion.LookRotation(m_DirToTarget); |
|
|
|
} |
|
|
|
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f)); |
|
|
|
transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0); |
|
|
|
// transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0);
|
|
|
|
|
|
|
|
orientationCube.UpdateOrientation(body, target.transform); |
|
|
|
} |
|
|
|
|
|
|
/// </summary>
|
|
|
|
public void CollectObservationBodyPart(BodyPart bp, VectorSensor sensor) |
|
|
|
{ |
|
|
|
|
|
|
|
m_DirToTarget = target.transform.position - body.position; |
|
|
|
//GROUND CHECK
|
|
|
|
sensor.AddObservation(bp.groundContact.touchingGround); // Is this bp touching the ground
|
|
|
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
void RewardFunctionMovingTowards() |
|
|
|
{ |
|
|
|
var movingTowardsDot = Vector3.Dot(orientationCube.transform.forward, |
|
|
|
Vector3.ClampMagnitude(m_JdController.bodyPartsDict[body].rb.velocity, maximumWalkingSpeed)); |
|
|
|
if (float.IsNaN(movingTowardsDot)) |
|
|
|
{ |
|
|
|
throw new ArgumentException( |
|
|
|
"NaN in movingTowardsDot.\n" + |
|
|
|
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+ |
|
|
|
$" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n"+ |
|
|
|
$" maximumWalkingSpeed: {maximumWalkingSpeed}" |
|
|
|
); |
|
|
|
} |
|
|
|
//var movingTowardsDot = Vector3.Dot(orientationCube.transform.forward,
|
|
|
|
// Vector3.ClampMagnitude(m_JdController.bodyPartsDict[body].rb.velocity, maximumWalkingSpeed));
|
|
|
|
//if (float.IsNaN(movingTowardsDot))
|
|
|
|
//{
|
|
|
|
// throw new ArgumentException(
|
|
|
|
// "NaN in movingTowardsDot.\n" +
|
|
|
|
// $" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
|
|
|
|
// $" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n"+
|
|
|
|
// $" maximumWalkingSpeed: {maximumWalkingSpeed}"
|
|
|
|
// );
|
|
|
|
//}
|
|
|
|
var movingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].rb.velocity, m_DirToTarget.normalized); |
|
|
|
AddReward(0.03f * movingTowardsDot); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void RewardFunctionFacingTarget() |
|
|
|
{ |
|
|
|
var facingReward = Vector3.Dot(orientationCube.transform.forward, body.forward); |
|
|
|
if (float.IsNaN(facingReward)) |
|
|
|
{ |
|
|
|
throw new ArgumentException( |
|
|
|
"NaN in movingTowardsDot.\n" + |
|
|
|
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+ |
|
|
|
$" body.forward: {body.forward}" |
|
|
|
); |
|
|
|
} |
|
|
|
//var facingReward = Vector3.Dot(orientationCube.transform.forward, body.forward);
|
|
|
|
//if (float.IsNaN(facingReward))
|
|
|
|
//{
|
|
|
|
// throw new ArgumentException(
|
|
|
|
// "NaN in movingTowardsDot.\n" +
|
|
|
|
// $" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
|
|
|
|
// $" body.forward: {body.forward}"
|
|
|
|
// );
|
|
|
|
//}
|
|
|
|
|
|
|
|
var facingReward = Vector3.Dot(m_DirToTarget.normalized, body.forward); |
|
|
|
AddReward(0.01f * facingReward); |
|
|
|
} |
|
|
|
|
|
|
|