Search Unity

[Solved/Mistake] 2D Rigidbody + Colliders (separate gameobjects) + Distance Joint

Discussion in 'Physics' started by msh91, Mar 23, 2019.

  1. msh91

    msh91

    Joined:
    Apr 22, 2017
    Posts:
    37
    - Current state:
    - Player gameobject is created at runtime
    - I need to change the origin of the player at runtime, so I've created a PlayerParent gameobject, and put Player as a child
    - Player gameobject has the colliders (polygon + circles). It has the shape, and it's origin is changing.
    - PlayerParent has the rigidbody. Otherwise, the the position of the Parent gameobject will always be the same.
    This can has many consequences, first one being it will mess with changing the origin.

    - Problem:
    - I'm trying to add a distance joint. It requires rigidbody on the same gameobject, so it should be added to the PlayerParent.
    However, it doesn't seem to work correctly, I'm assuming due to colliders being in the child
    (it does work when put on the child with the colliders)

    - Possible solutions:
    - Put rigidbody in child & make parent follow child.
    In script, set parent position to child, and child local position to 0. I'm not sure about it,
    but I'm pretty sure it will lead to some bad results since I'm interferring with the physics engine, but only with position.
    - Put colliders in parent. This means I'll need to update the colliders every time the origins are changing.
    Also, by "update" I mean calculate their new positions and shape (probably not so simple with a polygon collider).


    What do you think? what's the best option? any better one?

    p.s.
    I wasn't sure if this thread should be here or in 2D forum. Let me know if I should post it there instead.


    Edit:
    I feel stupid (sort of). It was all caused by me playing with the velocity in the PlayerParent. It seems to be a common problem though, and I'm not sure what to do with it yet. But it's definitely a different problem, so this post can even be deleted.
     
    Last edited: Mar 23, 2019