Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Best way to have child physicsbody entity move with parent entity with physicsbody

Discussion in 'Physics for ECS' started by BenMM, Jul 29, 2022.

  1. BenMM

    BenMM

    Joined:
    Jan 28, 2019
    Posts:
    16
    Hi,
    im i a situation where i have this gameobject hierarchy:

    Root:
    • physics shape
    • physics body
    Child1:
    • physics shape
    • physics body
    Child2:
    • physics shape
    • physics body
    Each child has its own physicsbody because i need to have the Child entity returned from a collision/Raycast.
    I want to be able to destroy a child if its collider is hit, but also need the parent to be hittable and return the hit entity.

    But since children with physics body get unparented when parent also has a physicsbody, i'm wonder what the best pratices are to have them move together/in-sync or not unparent at all.

    Most promising way i have found so far is using physics joints(Fixed Joint), but i'm somewhat unclear as to how to make it work.
    Very few examples avaliable, and the physics sample on github uses joint authoring components that are not avaliable in the physics package. I managed to make children move with the parent, by using the prismatic joint in the physics examples, although the cild orientation are wrong.

    Are there any other ways to achieve this?
    Or some help/tips with the joint approach?

    Cheers
     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,742
  3. BenMM

    BenMM

    Joined:
    Jan 28, 2019
    Posts:
    16
    Thanks SpookyCat, i was not aware the "old" joints could be converted.
    Works like a charm.