Search Unity

Rigidbody doesn't move with transform!!

Discussion in 'Physics' started by FeastSC2, Jun 2, 2019.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I realized that sometimes my Rigidbody is not being moved along with my transform's position. This is with a trigger collider and kinematic rigidbody.

    I move my gameobject with the rigidbody from position 1 to position 2 in the editor:
    The editor gizmos shows the collider is allegedly moved to position 2, however it's not being detected by my OnTriggerEnter function, instead OnTriggerEnter is being called in the position 1 where the collider/transform started(position 1).

    What can I do to update the Rigidbody's position to always be on the transform's position?

    PS: Whenever I edit the Rigidbody in the inspector, it syncs back and teleports to position 2.
     
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    How do you guys make your triggers interact with each other?
    If you don't know the answer to the first post it's alright. I just want to make a hitbox(trigger) always hit a hurtbox(trigger).

    In 2D, I added a rigidbody2D on both the triggers and it worked without problems. But somehow in 3D, it seems different.
     
  3. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    I'm definitely having the same issue as the first post. This issue was definitely not present for the same project and scene in 2018.2, but after upgrading to 2019.1, my kinematic rigidbodies do not move along with their parents. Their gizmos say they and their colliders are moving, but in the physics inspector, those colliders do not move.

    If anyone has a workaround or knows if this is intentional or is being fixed let me know!! ty

    Edit: Another Detail:
    This is occuring for me with a few examples of a Kinematic Rigidbody that is a child of a Rigidbody. When the parent rigidbody moves, the child thinks it has not moved. If i remove that Kinematic Rigidbody, its collider updates correctly in the physics debugger.

    It's as if the kinematic rigidbody is falling asleep even though its parent has momentum. This sounds like a reasonable thing for a rigidbody to do, but it definitely wasn't happening before.
     
    Last edited: Jun 3, 2019
    FeastSC2 likes this.
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Make a quick check that you still have the issue when Auto Sync Transforms turned on.
    This did not solve the problem for me, but I'm curious.

    upload_2019-6-3_5-58-14.png
     
  5. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    I do have Auto Sync Transforms on! This does seem like exactly what this checkbox is for haha
     
  6. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Yes, I have this issue as well.
     
  7. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    I tried using Physics.SyncTransforms() in LateUpdate() to see if maybe the checkbox just wasn't doing anything, but the collider is still not syncing. What does work is toggling gameObject.active on the kinematic rigidbody - but this is an unsatisfying solution because i have important OnDisable and OnEnable events on these objects, and i don't otherwise want to be toggling a gameobject's active state every frame for multiple objects.
     
    FeastSC2 likes this.
  8. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I read this thread @swanijam https://answers.unity.com/questions/199347/rigidbody-and-parenting-kinematic-rigidbodies.html

    Basically it is said that :
    it's not allowed to have a non-kinematic rigidbody in a structure when there is already a parent that has a rigibody.
    However, in my case, there are 2 rigidbodies (a "real" one on the parent, and a kinematic one on one of the children). Meaning that the I'm following the rule but I still get the issue mentioned above.

    I checked the documentation but I don't see information about this rule however. Do you mind clearing this up for us @Bunny83?
     
  9. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    Yep, i think i've seen this rule as well. My child rigidbodies are strictly kinematic and are mainly there to direct collision events between different parts of a complicated VR boat setup. It's been working perfectly for a long time and only broke in 2019, but i haven't seen any mention of the rules changing for 2019!
     
  10. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    You should never parent rigidbody to another rigidbody. It will lead to unexpected behaviour.
     
    FeastSC2 likes this.
  11. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    It's always worked before with kinematic rigidbodies - a kinematic rigidbody should just maintain its localPosition at all times, right?

    I wouldn't dream of using a non-kinematic nested rigidbody, though.
     
  12. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    And it seems like the kinematic rigidbody does know that its collider belongs at its localposition&rotation, too. When i turn the gameobject on and off, or toggle isKinematic, the collider updates to where it should be. It seems that the collider-transform syncing just isn't happening when a parent moves, which doesn't seem intentional as it's afaik an undocumented change.
     
  13. swanijam

    swanijam

    Joined:
    Nov 14, 2016
    Posts:
    23
    Maybe this is related to the upgrade from physX 3.3 to 3.4 that occured in Unity 2018.3? I jumped from 2018.2 to 2019.1, so it's possible the issue began in 2018.3 and not 2019.1 as I said.
     
  14. Morseliot

    Morseliot

    Joined:
    Jan 10, 2015
    Posts:
    70
    Hi guys,
    Also experiencing the same issue. It was alright in 2018.3.XX, however after swapping editor to 2019 all my "car drivers" behave as mentioned above.

    Does anyone found a solution?
     
  15. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I think it's like Vergil said:

    "You should never parent rigidbody to another rigidbody. It will lead to unexpected behaviour."
     
  16. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    20
    Maybe not exactly the same but, I had similar issue and ended up in this thread while looking for a solution.

    Basically, I am shooting cannonballs with rigidbodies from a ship with a main rigidbody. When they collide with a target, I make them kinematic rigidbody, disable their colliders and renderers to finally reset their transfrom positions back to start position. When doing it I realised similar behaviour like the one mentioned in this thread. Although their transforms are set to initial start positions, sometimes they move on spot, but sometimes they stay in between position 1 and 2 along with their colliders.

    Thinking about the whole process during reading this thread, I realised that first the cannonballs moving with physics update and then for an instant after the collision, resetting them in normal update might create this issue. Therefore adding a small and short co-routine for 0.1 second as a buffer for the transition solved my problem instantly. Maybe the reason is something else, but at least it solved my problem.
     
  17. HernandoNJ

    HernandoNJ

    Joined:
    May 13, 2018
    Posts:
    75
  18. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    I got around this by using Physics.SyncTransforms()