前往
大廳
主題

狼 靜立 V2

夏洛爾 | 2022-12-02 13:43:58 | 巴幣 0 | 人氣 144



Wolf Stand V2

實驗目標:
1.進入站立瞬間後,由於其實可能仍處於不穩定狀態,要再進入靜立狀態
2.進入站立瞬間後,可能面向並沒有瞄準目標,要轉向目標
3.使用Clamp Reward避免快速自殺

實驗設計:
1.任何弱點觸地皆失敗 (尾巴也是弱點)
2.非弱點肢體 (然而狼目前沒有非弱點肢體)
if(wolfBodies[i].damageCoef > 0f){clampReward += -0.01f * wolfBodies[i].damageCoef;}
3.
//Set: judge.endEpisode = true//Set: judge.episodeLength = 10f//Set: useClampReward = trueif(weaknessOnGround){if(inferenceMode){brainMode = BrainMode.GetUp;SetModel("WolfGetUp", getUpBrain);behaviorParameters.BehaviorType = BehaviorType.InferenceOnly;}else{//===Train Stand===AddReward(-1f);judge.outLife++;judge.Reset();return;//===Train Other===// brainMode = BrainMode.GetUp;// SetModel("WolfGetUp", getUpBrain);// behaviorParameters.BehaviorType = BehaviorType.InferenceOnly;}}else if(wolfRoot.localPosition.y < -10f){if(inferenceMode){brainMode = BrainMode.GetUp;SetModel("WolfGetUp", getUpBrain);behaviorParameters.BehaviorType = BehaviorType.InferenceOnly;}else{//===Train Stand===AddReward(-1f);judge.outY++;judge.Reset();return;//===Train Other===// brainMode = BrainMode.GetUp;// SetModel("WolfGetUp", getUpBrain);// behaviorParameters.BehaviorType = BehaviorType.InferenceOnly;}}else if(targetDistance > 500f){judge.Reset();}else{targetSmoothPosition = targetPositionBuffer.GetSmoothVal();headDir = targetSmoothPosition - stageBase.InverseTransformPoint(wolfHeadRb.position);rootDir = targetSmoothPosition - stageBase.InverseTransformPoint(wolfRootRb.position);flatTargetVelocity = rootDir;flatTargetVelocity.y = 0f;targetDistance = flatTargetVelocity.magnitude;Vector3 flatLeftDir = Vector3.Cross(flatTargetVelocity, Vector3.up);lookAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfHead.right * -1f, headDir));upAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfHead.up * -1f, Vector3.up));//LeanVector3 leanDir = flatTargetVelocity.normalized;spineLookAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfSpine.right * -1f, flatLeftDir));spineUpAngle = Mathf.InverseLerp(180f, 30f, Vector3.Angle(wolfSpine.up * -1f, leanDir));rootLookAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfRoot.forward, flatLeftDir));rootUpAngle = Mathf.InverseLerp(180f, 20f, Vector3.Angle(wolfRoot.up, leanDir));float velocityReward = GetVelocityReward(8f);float angularReward = GetAngularVelocityReward(10f);float standReward = (wolfLeftFeetBody.isStand? 0.25f : 0f) + (wolfRightFeetBody.isStand? 0.25f : 0f) + (wolfLeftHandBody.isStand? 0.25f : 0f) + (wolfRightHandBody.isStand? 0.25f : 0f);leftThighAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfLeftThigh.right, Vector3.up));leftCalfAngle = Mathf.InverseLerp(180f, 10f, Vector3.Angle(wolfLeftCalf.right, Vector3.up));rightThighAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfRightThigh.right, Vector3.up));rightCalfAngle = Mathf.InverseLerp(180f, 10f, Vector3.Angle(wolfRightCalf.right, Vector3.up));leftUpperArmAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfLeftUpperArm.right, Vector3.up));leftForeArmAngle = Mathf.InverseLerp(180f, 10f, Vector3.Angle(wolfLeftForeArm.right, Vector3.up));rightUpperArmAngle = Mathf.InverseLerp(180f, 0f, Vector3.Angle(wolfRightUpperArm.right, Vector3.up));rightForeArmAngle = Mathf.InverseLerp(180f, 10f, Vector3.Angle(wolfRightForeArm.right, Vector3.up));// ===Train Stand===if(Time.fixedTime - landingMoment > landingBufferTime){bool outVelocity = velocityReward > Mathf.Lerp(1f, 0.3f, (Time.fixedTime - landingMoment - landingBufferTime)/4f);bool outAngularVelocity = angularReward > Mathf.Lerp(1f, 0.5f, (Time.fixedTime - landingMoment - landingBufferTime)/5f);bool outSpeed = outVelocity || outAngularVelocity;float aimLimit = Mathf.Lerp(0f, 0.7f, (Time.fixedTime - landingMoment - landingBufferTime)/5f);float aimLimit2 = Mathf.Lerp(0f, 0.85f, (Time.fixedTime - landingMoment - landingBufferTime)/4f);bool outDirection = lookAngle < aimLimit2 || upAngle < aimLimit2 || spineLookAngle < aimLimit2 || rootLookAngle < aimLimit2;bool outMotion = spineUpAngle < aimLimit || rootUpAngle < aimLimit;if( outSpeed || outDirection || outMotion){AddReward(-1f);if(outSpeed){// Debug.Log("outSpeed");// Debug.Log("outVelocity: " + outVelocity);// Debug.Log("outAngularVelocity: " + outAngularVelocity);judge.outSpeed++;}if(outDirection){// Debug.Log("outDirection");// Debug.Log("lookAngle: " + lookAngle);// Debug.Log("upAngle: " + upAngle);// Debug.Log("spineLookAngle: " + spineLookAngle);// Debug.Log("rootLookAngle: " + rootLookAngle);judge.outDirection++;}if(outMotion){// Debug.Log("outMotion");// Debug.Log("spineUpAngle: " + spineUpAngle);// Debug.Log("rootUpAngle: " + rootUpAngle);judge.outMotion++;}judge.Reset();return;}}//===Train Stand===lastReward = (1f-velocityReward) * 0.01f + (1f-angularReward) * 0.01f+ (lookAngle + upAngle + spineLookAngle + spineUpAngle + rootLookAngle + rootUpAngle) * 0.005f + standReward * 0.01f+ (leftThighAngle + leftCalfAngle + rightThighAngle + rightCalfAngle + leftUpperArmAngle + leftForeArmAngle + rightUpperArmAngle + rightForeArmAngle) * 0.003f+ (1f - exertionRatio) * 0.006f;if(lookAngle > 0.9f && upAngle > 0.9f  && spineLookAngle > 0.9f  && rootLookAngle > 0.9f && velocityReward < 0.3f && angularReward < 0.5f && standReward > 0.9f&& leftThighAngle > 0.8f && rightThighAngle > 0.8f && leftUpperArmAngle > 0.8f && rightUpperArmAngle > 0.8f){//===Train Stand===// Debug.Log("Stand");totalReward += 0.01f;AddReward( 0.01f );//===Enter Run===// ConfirmArrived();// brainMode = BrainMode.Run;// SetModel("WolfTrain", runBrain);// behaviorParameters.BehaviorType = BehaviorType.Default;// landingMoment = Time.fixedTime;}//===Train Stand===if(useClampReward){lastReward = lastReward+clampReward;if(lastReward < 0f) lastReward = 0f;}totalReward += lastReward;AddReward( lastReward );}

//大致來說
1.鼓勵面向,並使用ForceSharping
2.鼓勵抑制速度和角速度,並使用ForceSharping
3.鼓勵雙腳觸地
4.鼓勵抑制出力
5.使用ClampReward

實驗時間:
Step: 5e7
Time Elapsed: 121925s (33.87hr)

實驗結果:
實驗結果為部份成功,部分失敗

狼的確可以靜立,但是會是斜向
因為引導向量設定又錯誤了

這裡是懶得換變數又沒寫註解又忘記的結果
Look在受身的確是視線向量,但在靜力時是側面正交向量

所以才導致狼側身,而且又無法活過ForceSharping,而訓練時間變很長

尾巴部分是嘗試改成非弱點,希望狼完全不要用尾巴來移動,意外尾巴翹翹的很可愛,但是尾巴不能觸地也導致訓練變久,因為尾巴很容易亂甩

下個實驗將進行狼靜立
1.修正Look應為SideLook

創作回應

更多創作