|
|
|
|
|
|
public Transform leg3Lower; |
|
|
|
|
|
|
|
[Header("Joint Settings")] [Space(10)] JointDriveController m_JdController; |
|
|
|
Vector3 m_DirToTarget; |
|
|
|
float m_MovingTowardsDot; |
|
|
|
float m_FacingDot; |
|
|
|
|
|
|
|
|
|
|
public override void Initialize() |
|
|
|
{ |
|
|
|
//Spawn an orientation cube
|
|
|
|
Vector3 oCubePos = hips.position; |
|
|
|
Vector3 oCubePos = body.position; |
|
|
|
m_DirToTarget = target.position - body.position; |
|
|
|
|
|
|
|
//Setup each body part
|
|
|
|
m_JdController.SetupBodyPart(body); |
|
|
|
|
|
|
/// </summary>
|
|
|
|
void RewardFunctionMovingTowards() |
|
|
|
{ |
|
|
|
m_MovingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].rb.velocity, m_DirToTarget.normalized); |
|
|
|
m_MovingTowardsDot = Vector3.Dot(m_OrientationCube.transform.forward, m_JdController.bodyPartsDict[body].rb.velocity); |
|
|
|
AddReward(0.03f * m_MovingTowardsDot); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void RewardFunctionFacingTarget() |
|
|
|
{ |
|
|
|
m_FacingDot = Vector3.Dot(m_DirToTarget.normalized, body.forward); |
|
|
|
AddReward(0.01f * m_FacingDot); |
|
|
|
AddReward(0.01f * Vector3.Dot(m_OrientationCube.transform.forward, body.forward)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public override void OnEpisodeBegin() |
|
|
|
{ |
|
|
|
if (m_DirToTarget != Vector3.zero) |
|
|
|
{ |
|
|
|
transform.rotation = Quaternion.LookRotation(m_DirToTarget); |
|
|
|
} |
|
|
|
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f)); |
|
|
|
|
|
|
|
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void OnDrawGizmosSelected() |
|
|
|
{ |
|
|
|
if (Application.isPlaying) |
|
|
|
{ |
|
|
|
Gizmos.color = Color.green; |
|
|
|
Gizmos.matrix = m_OrientationCube.transform.localToWorldMatrix; |
|
|
|
Gizmos.DrawWireCube(Vector3.zero, m_OrientationCube.transform.localScale); |
|
|
|
Gizmos.DrawRay(Vector3.zero, Vector3.forward); |
|
|
|
} |
|
|
|
} |
|
|
|
} |