0
\$\begingroup\$

A bit of a newb to Unity & game development. I have built a very basic lunar lander ship and made some RCS thrusters out of cubes and cylinders to attach to the fuselage of the ship. However, whenever I apply main thrust, the ship moves, but the RCS thrusters remain in their original location. Is there a known method for having multiple "child" game objects "stick" to a parent gameobject?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Say you have two GameObjects p and c. You can make c a child of p by dragging c into p in the Hierarchy panel. See the documentation.

This is a basic fundamental of the Unity Editor. If you did not know how to do this already, you should take some time to learn how to use the Editor. Try reading the documentation and going through tutorials. Also, basic questions like this can generally be answered with a simple web search.

Note: If a child has a Rigidbody, it will move independently of its parent unless you add a Joint or Constraint (as DMGregory noted, Joints are better for Rigidbodies). If you want the children to be fixed in place relative to the parent, it's probably better not to give them a Rigidbody component unless you have a specific need for it.

If you wanted the thrusters to be able to apply forces to the lander, one thing you can do instead is use Rigidbody.AddForceAtPosition() to apply the force directly to the lander's Rigidbody.

\$\endgroup\$
8
  • \$\begingroup\$ Ahhhh...so, it sounds like I did it right by adding the thruster to the main lander object in the hierarchy pane. But because I added a Rigidbody component to each thruster, they now track as separate gameobjects. Is that a proper interpretation? \$\endgroup\$
    – Skittles
    Apr 12 at 0:17
  • 1
    \$\begingroup\$ @Skittles If a thruster has a Rigidbody, it will move independently of its parent (the lander). There are some exceptions - if the thruster has a Constraint component, if any of the position "Constraints" in the Rigidbody component are selected (note these are settings in the Rigidbody, not separate components), or if the thruster's Rigidbody has "is kinematic" checked. Generally I would recommend not putting Rigidbodies on the thrusters (they can still have colliders), but it will depend on your specific goals. \$\endgroup\$
    – Kevin
    Apr 12 at 0:24
  • \$\begingroup\$ I updated the answer with a note about using Rigidbody.AddForceAtPosition(). \$\endgroup\$
    – Kevin
    Apr 12 at 0:26
  • \$\begingroup\$ @Kevin - My desired result is that I would like to apply force at the thruster nozzle and have it effect the parent by imposing a rotation relative to the axis of the thruster's position on the fuselage. So, is it safe to assume that the AddForceAtPosition will do what it sounds like? Adding force at the thruster position relative to the parent? \$\endgroup\$
    – Skittles
    Apr 12 at 1:07
  • \$\begingroup\$ @Skittles Yep. As noted in the documentation, "As a result this will apply a torque and force on the object." \$\endgroup\$
    – Kevin
    Apr 12 at 1:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .