Skip to content

Commit

Permalink
【MA基礎開発】SpyAgentのセンサ系の見直し。各種ターゲットの検出にRayPerceptionSensor3Dではなく、unity付…
Browse files Browse the repository at this point in the history
…随のrayセンサを使う方法に転舵。 #1 #14

RayPerceptionSensor3Dでは検出したオブジェクトの位置情報をC#側で受け取る方法が見つからないため。
また、イベントハンドラーが発火しないのは、RayPerceptionSensor3DとRayは異なる存在であるため、RayPerceptionSensor3Dの検出では発火しない。
  • Loading branch information
tsyu1234 committed Feb 26, 2024
1 parent f2e2905 commit e09ad66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
9 changes: 9 additions & 0 deletions MAEasySimulator/Assets/SpyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

public class SpyAgent : Agent {


[Header("Sensor Settings")]
public int SensorCount = 5;
public float SensorDistance = 10f;

private Transform Sensor;
private float rayDistance = 40f; // レイキャストの距離
//TODO:以下複数の避難所を検出する場合の対応
Expand All @@ -22,6 +27,8 @@ public class SpyAgent : Agent {
private OnFindShelter _onFindShelter;
private string LogPrefix = "[Agent Spy]";
private Vector3 StartPosition;

private Ray SpySensor;

void Start() {
_controller = GetComponent<DroneController>();
Expand All @@ -33,6 +40,7 @@ void Start() {
_controller.onChargingBattery += OnChargingBattery;
Sensor = transform.Find("Sensor");
StartPosition = transform.localPosition;
SpySensor = new Ray(Sensor.position, Sensor.forward);
}

public override void OnEpisodeBegin() {
Expand All @@ -58,6 +66,7 @@ public override void CollectObservations(VectorSensor sensor) {
}
sensor.AddObservation(targetPos);
sensor.AddObservation(isFindTarget);
Debug.DrawRay(SpySensor.origin, SpySensor.direction * 10, Color.red, 5);
}

public override void OnActionReceived(ActionBuffers actions) {
Expand Down
29 changes: 0 additions & 29 deletions MAEasySimulator/Assets/SpyAgent.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 4346805486820663787}
- component: {fileID: 782739389039547031}
m_Layer: 0
m_Name: Sensor
m_TagString: Untagged
Expand All @@ -32,34 +31,6 @@ Transform:
m_Father: {fileID: 5917736595786903999}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 44.045, y: 0, z: 0}
--- !u!114 &782739389039547031
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6291193101612035988}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bb6b867a41448888c1cd4f99643ad71, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: RayPerceptionSensor
m_DetectableTags:
- Shelter
m_RaysPerDirection: 3
m_MaxRayDegrees: 70
m_SphereCastRadius: 0.5
m_RayLength: 40
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291
m_ObservationStacks: 1
m_AlternatingRayOrder: 1
rayHitColor: {r: 1, g: 0, b: 0, a: 1}
rayMissColor: {r: 1, g: 1, b: 1, a: 1}
m_StartVerticalOffset: 0
m_EndVerticalOffset: 0
--- !u!1 &6760585562241815342
GameObject:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit e09ad66

Please sign in to comment.