Ml-agents: RayPerception in Pushblock

Created on 13 Dec 2018  路  4Comments  路  Source: Unity-Technologies/ml-agents

I'm going through the examples and I tried to understand the script rayperception. I understood that it is drawing the rays around the agent. But I couldn't figure out what it is doing beyond of this. The addVectorOrbs is awaiting a vector but we are giving a list of vectors. But I don't know which information the vectors in the list contains. Can I just use this code to draw the rays? If yes, is there something missing that I should insert?

```csharp

pragma strict

private var whenNeeded : boolean;

function Update(){

 if(whenNeeded){

     DetectEnemy(transform.position, 20);
 }

}

function DetectEnemy(center: Vector3, radius: float) {

 var hitColliders = Physics.OverlapSphere(center, radius);

 for (var i = 0; i < hitColliders.Length; i++) {
     print(hitColliders[i].tag);
     // collect information on the hits here
 }

}
```

discussion

Most helpful comment

Hi @Semih67
your javascript code excerpt uses a sphere to detect collisions. However, do not use javascript in Unity, because it is deprecated by now.

For what reason do you want to use raycasts? Maybe add a small drawing or a more detailed description of your use-case.

Maybe have a look at this tutorial if you are new to raycasts:
https://www.youtube.com/watch?v=THnivyG0Mvo

All 4 comments

RayPerception.Perceive returns a list of floats, not a list of vectors.
The list of floats goes as follows :

  • For each angle a ray is drawn
  • For each ray, we add (number of detectable objects + 1) floats.

    • a one hot vector of length number of detectable objects to indicate what type of object is being hit by the ray

    • a float between 0 and 1 indicating the distance to the colliding object

    • a float either 0 or 1. 1 if the hit object is unknown, 0 otherwise

This gives #angles x (#detectableObjects + 2)

I am not sure what your code does but it does not draw rays. this code will (I think) print the tag of all the objects around center under a distance of radius. If you think that is relevant information, you can definitely give that to your agent as long as you can encode it into a vector of floats of fixed length.

Hi @Semih67
your javascript code excerpt uses a sphere to detect collisions. However, do not use javascript in Unity, because it is deprecated by now.

For what reason do you want to use raycasts? Maybe add a small drawing or a more detailed description of your use-case.

Maybe have a look at this tutorial if you are new to raycasts:
https://www.youtube.com/watch?v=THnivyG0Mvo

Thank you for the discussion. We are closing this issue due to inactivity. Feel free to reopen it if you鈥檇 like to continue to discussion though.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DVonk picture DVonk  路  3Comments

green4you picture green4you  路  4Comments

scotthovestadt picture scotthovestadt  路  4Comments

Sohojoe picture Sohojoe  路  3Comments

mattinjersey picture mattinjersey  路  3Comments