V2.8 移动算法更新

过去X与Y可同时达到maxspeed致使速度会超过maxspeed,本次修正了该错误。
追加移动Penalty。
This commit is contained in:
2023-02-15 21:06:57 +09:00
parent 5ccb06c545
commit faa4e7b065
6 changed files with 386 additions and 367 deletions
+16 -5
View File
@@ -33,9 +33,10 @@ public class AgentWithGun : Agent
public Camera thisCam;
[Header("GetAxis() Simulate")]
public float MoveSpeed = 2.0f;
public float MoveSpeed = 9.0f;
public float vX = 0f;
public float vZ = 0f;
public Vector3 thisMovement;
public float acceleration = 0.1f; // 加速度
public float mouseXSensitivity = 100;
public float mouseYSensitivity = 200;
@@ -107,7 +108,7 @@ public class AgentWithGun : Agent
// moveAgent 用于模拟Input.GetAxis移动
public void moveAgent(int vertical, int horizontal)
{
Vector3 thisMovement;
// Vector3 thisMovement;
if (horizontal != 0)//当按下按键(水平方向)
{
@@ -170,9 +171,13 @@ public class AgentWithGun : Agent
vZ = 0;
}
}
thisMovement = (transform.forward * vZ + transform.right * vX) * MoveSpeed;
thisMovement = (transform.forward * vZ + transform.right * vX);
//PlayerController下的.Move为实现物体运动的函数
//Move()括号内放入一个Vector3类型的量,本例中为Player_Move
if (thisMovement.magnitude > MoveSpeed)
{
thisMovement = thisMovement.normalized * MoveSpeed;
}
PlayerController.Move(thisMovement * Time.deltaTime);
// update Key Viewer
}
@@ -362,7 +367,7 @@ public class AgentWithGun : Agent
// ------------Reward--------------
// rewardCalculate 计算本动作的Reward
public float rewardCalculate(float sceneReward,float mouseX)
public float rewardCalculate(float sceneReward,float mouseX,float movement)
{
float epreward = 0f;
// 击杀reward判断
@@ -383,6 +388,7 @@ public class AgentWithGun : Agent
epreward += ballistic() + sceneReward;
// facing reward
epreward += facingReward();
// Penalty
// spin penalty
spinRecord.Add(mouseX);
if (spinRecord.Count >= paramContainer.spinRecordMax)
@@ -398,6 +404,11 @@ public class AgentWithGun : Agent
{
epreward -= Math.Abs(mouseX) * paramContainer.mousePenalty;
}
// move penalty
if (movement != 0)
{
epreward -= paramContainer.movePenalty;
}
return epreward;
}
@@ -484,7 +495,7 @@ public class AgentWithGun : Agent
float sceneReward = 0f;
float endReward = 0f;
(finishedState, sceneReward, endReward) = targetCon.checkOverAndRewards();
float thisRoundReward = rewardCalculate(sceneReward+ endReward,Mouse_X);
float thisRoundReward = rewardCalculate(sceneReward+ endReward,Mouse_X,Math.Abs(vertical)+Math.Abs(horizontal));
if (hudController.chartOn)
{
EnvUICon.updateChart(thisRoundReward);
+2 -2
View File
@@ -76,8 +76,8 @@ public class ParameterContainer : MonoBehaviour
public float shootTargetAreaReward = 5.0f;
[Header("Penalty Rewards")]
[Tooltip("Speed Penalty Reward")]
public float speedPenalty = 0f;
[Tooltip("move Penalty Reward")]
public float movePenalty = 0f;
[Tooltip("spiiiiiiin Panalty Reward")]
public float spinPenalty = 0f;
[Tooltip("while move mouse a little bit's penalty")]
+3 -3
View File
@@ -264,8 +264,8 @@ public class TargetController : MonoBehaviour
(nowDistance, inArea) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
envUICon.updateTargetGauge(blockCont.thisBlock.firebasesBelong, blockCont.thisBlock.belongMaxPoint);
float areaTargetReward = getDistanceReward(nowDistance, inArea);
// if (blockCont.thisBlock.firebasesBelong >= blockCont.thisBlock.belongMaxPoint)
if(inArea != 0)
//if(inArea != 0)
if (blockCont.thisBlock.firebasesBelong >= blockCont.thisBlock.belongMaxPoint)
{
// win
// let the area belongs to me
@@ -284,7 +284,6 @@ public class TargetController : MonoBehaviour
else
{
// keep on keeping on!
thisReward = areaTargetReward;
endReward = 0;
endTypeInt = (int)EndType.Running;
@@ -392,6 +391,7 @@ public class TargetController : MonoBehaviour
float thisSceneReward = 0f;
if (inarea != 0)
{
// in area
thisSceneReward = paramCon.inAreaReward;
}
else