Search Unity

How to create RayPerceptionSensorComponent3D without affected transform's rotation?

Discussion in 'ML-Agents' started by yepfuk, Mar 9, 2020.

  1. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    Hi, I want to use ray perception sensor component. I attach it to my agent gameobject, it works but it also affected by agent's rotation which I don't want. How to create constant rays without affecting the agent's rotation?
     
  2. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    I solved it by;
    - Create a new empty child gameobject.
    - Attach this a new script that responsable for fixing the rotation.
    - Add the ray perception sensor to this child gameobject.
     
  3. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    Unfortunately, I don't have a better solution than that currently. We can think about adding a more general solution for this in the future.

    Just curious, what's the use case for this?
     
  4. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    I used it on a 2.5D platformer game where the characters are rotate when they move.
     
  5. xbayrockx

    xbayrockx

    Joined:
    Jan 13, 2020
    Posts:
    4
    this doesnt work for me. i am updating the rotation in Update() with this.transform.rotation = Quaternion.identity;
    however when using e.g. --time-scale 100 the update doesnt sync up properly with the sensor raycasts
     
  6. xbayrockx

    xbayrockx

    Joined:
    Jan 13, 2020
    Posts:
    4
    and its just a simple ball that is rolling about that i want a raycast sensor for to detect the ground/objects etc
     
  7. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    Hi, the script attached to this gameobject is;


    Code (CSharp):
    1. private Quaternion _initialRotation;
    2.  
    3. private void Awake(){
    4.     _initialRotation = transform.rotation;
    5. }
    6.  
    7. private void Update(){
    8.    transform.rotation = _initialRotation;
    9. }
     
  8. xbayrockx

    xbayrockx

    Joined:
    Jan 13, 2020
    Posts:
    4
    hey. as i said rotation in Update() does not work properly when increasing the time scale if the sensor is attache. I also added these lines to FixedUpdate() and LateUpdate() but still the same problem. to solve this problem I ended up changing the hierarchy of my agent so that the Agent component was on the parent object with DecisionRequestor and BehaviorParameters, the actual rotating ball was a separate child game object with no ml-agent components attached, the sensor was again another separate child game object with the sensor attached. this way the sensor never gets rotated but it will still get its position moved so i aligned it with this.transform.position = ball.transform.position; instead.
     
    ItzMeStellar likes this.