Hi, is there a concept of center of gravity in Unity, across multiple colliders attached to one game object.
for example, if I create a large rectangle sprite in 2D, attach 3 2D circle colliders evenly across the rectangle (one in the middle and one on each end). Then, slowly push it off a ledge, should it act as though the 3 were connected and fall off after it passes the halfway mark?
I guess the question is, how does unity calculate center of gravity in general? I have several game objects with child objects that have various coliders, and i want them to act like one large object when it comes to gravaity and buoyancy.
Any experienced developers out there understand how this works?
You are using rigidbody’s so yes it should have a real center of gravity(in 3D anyway, I’m not quite sure in 2D but suspect it is the same). You need to add 1(only one!) rigidbody onto the parent object. Do not apply any to the child collider objects!. The one rigidbody at the top level will then combine these child colliders into one object for its calculations which will give you what you want. Look up compound colliders in the Unity Docs for more info.
Mr Soad, I really appreciate the time and thought you’ve given up for me!
This is very helpful. I think I’ve narrowed the problem down to the floating script I’m using. The boat works perfectly when I push if off a cliff, but when I drop it in my water it just won’t rotate, even if I put it along side the water with only the tip sticking in, the upward force is even across the whole boat and it stays perfectly horizontal. I think this is because the code that floats the boat (this.rigidbody2D.AddForce) applies the upforce equally across the whole rigidbody and not to the collider that is hitting it. The youtube script you mentioned does a similar thing.
I think i need to either find a way to apply the force to just the collider(s) that are in the water, or find a way to add multiple rigid bodies to one parent gameobject.