Ejemplo n.º 1
0
 public List<float> GetSensorData()
 {
     // check for the sensor data
     RayPerceptionInput input = distanceSensorComponent.GetRayPerceptionInput();
     RayPerceptionOutput output = RayPerceptionSensor.Perceive(input);
     var list = output.RayOutputs;
     //RayPerceptionOutput.RayOutput output0 = (RayPerceptionOutput.RayOutput)list.GetValue(0);
     //print(output0.HitFraction);
     List<float> hitFractions = new List<float>();
     foreach (var listItem in list)
     {
         RayPerceptionOutput.RayOutput outputRef = (RayPerceptionOutput.RayOutput)listItem;
         hitFractions.Add(outputRef.HitFraction);
     }
     return hitFractions;
 }
Ejemplo n.º 2
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         ReSetPosition();
     }
     if (Input.GetKeyDown(KeyCode.P))
     {
         // 레이퍼셉션의 각 태그번호를 가져오는 코드
         r3 = RayPerceptionSensor.Perceive(r2);
         for (int i = 0; i < r3.RayOutputs.Length; i++)
         {
             print(r3.RayOutputs[i].HitTagIndex + ", " + i + "번째");
         }
     }
 }
Ejemplo n.º 3
0
    public override void OnActionReceived(float[] vectorAction)
    {
        // 만일 vectorAction의 0번 값이 0이면 왼쪽으로 회전하고, 1이면 회전하지 않고, 2면 오른쪽으로 회전하게 하고 싶다.
        float rotvalue = vectorAction[0] - 1;

        rotY += rotvalue * rotSpeed;

        transform.localEulerAngles = new Vector3(0, rotY, 0);
        // 만일 vectorAction의 1번 값이 0이면 가만히 있고, 1이면 앞으로 움직인다.
        Vector3 dir = transform.forward * vectorAction[1];

        transform.position += dir * moveSpeed * Time.deltaTime;



        //가만히 있을 때 받는 벌점
        if (transform.position == previousPos)
        {
            AddReward(-1.0f / gm.CustomMaxStep);
        }
        // 탈출 시간에 따른 벌점
        AddReward(-1.0f / gm.CustomMaxStep);

        // 불이랑 가까워 졌을 때 받는 벌점
        float nowFireDisFromPlayer = Vector3.Distance(transform.position, transform.position);
        float preFiredisFromPlayer = Vector3.Distance(transform.position, previousPos);

        if (preFiredisFromPlayer >= nowFireDisFromPlayer)
        {
            AddReward(-10.0f / gm.CustomMaxStep);
        }

        if (detectEixt == false)
        {
            // 레이퍼셉션의 각 태그번호를 가져오는 코드
            r3 = RayPerceptionSensor.Perceive(r2);
            for (int i = 0; i < r3.RayOutputs.Length; i++)
            {
                //print(r3.RayOutputs[i].HitTagIndex + ", " + i + "번째");
                // 만약 레이에서 출구가 감지되면 상점
                if (r3.RayOutputs[i].HitTagIndex == 1)
                {
                    AddReward(1.0f);
                    detectEixt = true;
                    break;
                }
            }
        }
        else
        {
            // 레이퍼셉션의 각 태그번호를 가져오는 코드
            r3 = RayPerceptionSensor.Perceive(r2);
            for (int i = 0; i < r3.RayOutputs.Length; i++)
            {
                //print(r3.RayOutputs[i].HitTagIndex + ", " + i + "번째");
                // 만약 레이에서 출구가 감지되지 않는다면 벌점
                if (r3.RayOutputs[i].HitTagIndex == 1)
                {
                    break;
                }
                if (i == r3.RayOutputs.Length)
                {
                    AddReward(-10.0f);
                }
            }
        }

        //전프레임 위치 저장
        previousPos = transform.position;
        // 불을 감지했을 때 결정할 함수(네비게이션)
        //OnDetectFireDecision();
    }