2

Say you want to let your users create a 2D airship (side view) made up of components. One component could be a floating balloon, another could be a storage room, etc.

And say you want this airship to have physics applied to it as a whole, with each component playing a part in this. For example, balloons would take away from its down force and other compartments would apply down force to it.

At the same time, the whole airship works as a whole (or at least the only physical separation would be between floater components and the others, which apply weight), so physics are applied to it as if it was one body.

Now, how can this be managed? How can I customize a game object via a script, giving it different components with different weights, and have it behave like it was a single premade object?

I'm sorry if the question is simple, but I'm only getting started with unity. Thank you very much!

TL;DR: Customizable airship gameobject with different components that have different weights. How to make it behave as a single physics entity and manage its different components?

1 Answer 1

1

I'm not sure that I completely understood the question :D You mean having a game object, that has some child game objects, each with individual Collider and Rigidbody, and the Rigidbody physics applied to the parent game object? You can use joint colliders for this purpose such as HingeJoint2D, and set the parent's Rigidbody as ConnectedRigidBody.

(And instead of the word "component", use child or part or sth else to prevent ambiguity. 'Cuz the components in Unity3D are stuff like scripts, rigidbody, collider, etc. which are attached to game objects.)

Sign up to request clarification or add additional context in comments.

3 Comments

I think transform parenting is what I'm looking for. It's actually interesting that there is not many information on how to approach a system like this (complex 2d object and parenting) on the web, aside from the official docs.
You can use joints with parenting also. I don't think your case will be solved only with transform parenting. Because for example, if you have a parent that has a Rigidbody and a child with another Rigidbody, the child's physics works independently (i.e. the child doesn't affect the parent, if it's a hot-air balloon, the balloon part goes up while the body is still going down) unless you connect them with something like joints.
Yes, parenting for the bottom part of the airship, and have it connected to the floating part via joints :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.