Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Adding Parent component break Collider

Discussion in 'Physics for ECS' started by Pabi, Sep 30, 2020.

  1. Pabi

    Pabi

    Joined:
    Feb 13, 2016
    Posts:
    48
    I'm trying to integrate a navigation system in my game and the Navigation system add Parent component. I discover the moment I add a Parent Component, the Collider stop working and passthrough my other colliders (the ground).

    I'm not sure of the correct way to fix this. Do I have the assign a new collider / create a copy of the current collider AFTER I add the parent component? I don't know how to create colliders from code as right now I use the Physics Shape and Physics Body authoring and all worked well.

    Any Ideas ? Thanks!
     
  2. hellaeon

    hellaeon

    Joined:
    Jul 20, 2010
    Posts:
    90
    Hey mate, I experienced the same thing with Triggers. In the end I just removed the parent component, and instead calculate the position of the child based on the local to world matrix (LTW) of the parent.

    This causes some painful dramas as well due to the order of calculations.
    For the gameplay I am attempting I do not need the rotation of the parent as the parent is just a reference point, so all I save is the parents position. This position is then used in the child's movement system to calculate where the child should go in relation to the parent.

    If you need it start with math.inverse(LTW(child)) * LTW(parent)
    To then extract the new position from the matrix - new Rigidtransform(TM)

    I ended up convinced it was an ordering thing. I have some prefabs ready to go with the physics components, so my thinking is runtime creation of entities and adding physics then would fix it.
    However, I can move past only due to the gameplay I have.
     
  3. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Unlike static bodies, Unity Physics assumes that dynamic bodies are not in a hierarchy. UP reads and writes the Translation and Rotation component values as if they are world space. Processing the hierarchy could be problematic for performance and so this design was made fairly early on.

    Do you really need the Parent component on dynamic bodies?