Skip to content

Commit

Permalink
【MA基礎開発】 #19 物質位置初期化の問題は解消。エージェントが物質を取得した際に位置が不正。
Browse files Browse the repository at this point in the history
  • Loading branch information
tsyu1234 committed Mar 28, 2024
1 parent 47ba048 commit 2e102ff
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 11 deletions.
4 changes: 2 additions & 2 deletions MAEasySimulator/Assets/Scenes/test0.4.unity
Git LFS file not shown
8 changes: 8 additions & 0 deletions MAEasySimulator/Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SurpplieAgent : Agent {
public bool isGetSupplie = false; // 物資を持っているかどうか
public bool wasRelease = false; // 物資を投下したかどうか
//public bool isOnShelter = false; // 避難所の範囲内にいるかどうか
public bool canGetSupplie = false; // 物資を取得できるかどうか
public bool canGetSupplie = true; // 物資を取得できるかどうか

public GameObject Supplie; // 物資
private DroneController Ctrl;
Expand All @@ -41,7 +41,6 @@ void Start() {
StartPosition = transform.localPosition;

GetSupplie();
Supplie = transform.Find("BoxReady").gameObject;
SurpplieBox box = Supplie.GetComponent<SurpplieBox>();
box.onLandingShelter += OnLandingSurpplieForShelter;
box.inRangeCanGet += InRangeSurpplie;
Expand All @@ -63,21 +62,29 @@ public override void CollectObservations(VectorSensor sensor) {

public override void OnActionReceived(ActionBuffers actions) {
Ctrl.FlyingCtrl(actions);

var doGetting = actions.DiscreteActions[0] == 2 ? true : false;
var doRelease = actions.DiscreteActions[0] == 1 ? true : false;
var doNothing = actions.DiscreteActions[0] == 0 ? true : false;

if (doRelease) {
ReleaseSupplie();
} else if (doGetting) {
GetSupplie();
} else if (doNothing) {
//何もしない

}
}

public override void Heuristic(in ActionBuffers actionsOut) {
Ctrl.InHeuristicCtrl(actionsOut);
actionsOut.DiscreteActions.Array[0] = 0;
if(Input.GetKey(KeyCode.R)) {
actionsOut.DiscreteActions.Array[0] = 1;
} else {
actionsOut.DiscreteActions.Array[0] = 0;
}
if(Input.GetKey(KeyCode.G)) {
Debug.Log("Heuristic: GetSupplie");
actionsOut.DiscreteActions.Array[0] = 2;
}
}

Expand Down Expand Up @@ -139,7 +146,12 @@ private void OutRangeSurpplie() {
canGetSupplie = false;
}

private void GetSupplie() {
private void GetSupplie(bool force=false) {
Debug.Log(LogPrefix + "canGetSupplie" + canGetSupplie);
if(!canGetSupplie && !force) {
return;
}
Debug.Log(LogPrefix + "GetSupplie");
//物資の重力を無効化
Supplie.GetComponent<Rigidbody>().useGravity = false;
// 物資を取る : オブジェクトの親をドローンに設定
Expand Down Expand Up @@ -176,7 +188,8 @@ private void Reset() {
//バッテリーをリセット
Ctrl.batteryLevel = 100;
Supplie.GetComponent<SurpplieBox>().Reset();
GetSupplie();
canGetSupplie = true;
GetSupplie(true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void OnTriggerEnter(Collider other) {
Reset();
} else if (other.CompareTag("Obstacle")) {
Debug.LogWarning("SurpplieBox: OnCrash");
Reset();
//Reset();
}
}

Expand All @@ -47,7 +47,7 @@ private void OnTriggerStay(Collider other) {
}

public void Reset() {
Vector3 renewPos = new Vector3(StartPosArea.transform.localPosition.x, StartPosArea.transform.localPosition.y + 5, StartPosArea.transform.localPosition.z);
Vector3 renewPos = new Vector3(StartPosArea.transform.localPosition.x, StartPosArea.transform.localPosition.y, StartPosArea.transform.localPosition.z);
transform.localPosition = renewPos;
transform.localRotation = Quaternion.Euler(0, 0, 0);
Debug.Log("Reset Supplie");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2e102ff

Please sign in to comment.