简体   繁体   中英

Unity ML Agents Ray Perception Sensor 2D not showing collisions

I am still relatively new to the Unity environment and am currently working with reinforcement learning and ML agents. For this I wanted to add an agent to the 2D platformer.

I have attached two ray perception sensors to my agent. Unfortunately I can't get any hits with these sensors, at least they are not displayed as usual with a sphere in the gizmos.

带小玩意的场景视图

The sensors are casting rays, but like you see in the image, they are not colliding.

The ray perception sensor are childs of the agent, defined in its prefab. I defined the sensors to collide with 4 tags: Untagged, ground, enemy and coin

I assigned the coin tag to the token, the enemy tag to the enemy and the ground tag to the tilemap forming the ground. The token has a circle collider, while the enemy has an capsule collider. On the tilemap there is a tilmap collider.

I would now expect the sensor to collide with the token, enemy and ground and display these hits in spheres, but it does not.
So, what am I doing wrong?

RayPerceptionSensor2D的定义

After a lot more investigation i figured out the problem myself:

The tags where correctly configured, but i had an misunderstanding in the Ray Layer Mask.

Ray Layer Mask

Previously i had configured it to "Everything"/"Default" which resulted in a collision in the sensor itself and seems not right (Despite the player tag was not in the detagtable tags).

After i created more layers and assigned my targets to these layers, everything starts working as intended.

Working Result

Maybe this answer will help someone, having similar issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM