0
\$\begingroup\$

I'm brand new(ish) to Unity with a strong programming background. I understand the basics of "how to roll a ball" in Unity, but I have a custom model I made in Blender which I have imported as a two objects. What I would like to do is roll the ball while keeping the top part (called "Carrier") fixed above it. It was exported from Blender as one mesh, but I have unpacked it to use in Unity.

Mesh with hierarchy

My thinking so far is to use a Rigidbody on the ball as a sub-component of the top part, which also has a Rigidbody, and apply a ConfigurableJoint from the ball to the carrier. So far, nothing seems to stay where I want it. Can someone put me on the right track for configuring the joint? Or if I'm completely on the wrong track, plz halp?

Here's what I tried so far:

enter image description here

but the top just flops around (sticking upright, because I locked the X and Z rotations).

UPDATE:

I tried @Philipp's suggestion (thanks!), but the whole thing separates when the game starts:

ball separating from carrier

I tried with and without a rigidbody on the carrier, as well as several configurations of parenting (including totally separate objects).

\$\endgroup\$
4
  • \$\begingroup\$ It looks like this recent Q&A might also apply to your use case. \$\endgroup\$
    – DMGregory
    Oct 29 '21 at 21:25
  • \$\begingroup\$ That does look like what I'm trying to do; thanks! I didn't see anything in there about joints or anything... What would the hierarchy look like? Do you need a single rigidbody or multiple? Or just apply the script (with modifications) to my carrier object and leave the rigidbody part to the ball? \$\endgroup\$
    – Andy
    Oct 30 '21 at 3:42
  • \$\begingroup\$ Myself, I think it's simpler to move the carrier with a script rather than a joint setup. \$\endgroup\$
    – DMGregory
    Oct 30 '21 at 12:08
  • 1
    \$\begingroup\$ When you received an answer which does not work for you, then it would be good to comment on the answer, not edit your question. That way the author of the question gets notified and might be able to help you. But when you edit your question, then the answer author does not get notified. \$\endgroup\$
    – Philipp
    Oct 30 '21 at 12:21
0
\$\begingroup\$

Instead of using joints, I would just use a simple follower script:

public class FollowOtherObject : MonoBehaviour {

    public Transform other;

    FixedUpdate() { 
        if (other != null) {
            transform.position = other.position;
        }
    }
}
  1. Make the ball and the carrier two separate game objects.
  2. Assign the script above to the carrier
  3. Assign the ball to the inspector-property "other" of the FollowOtherObject component of the carrier.

This will glue the following object to the center of the followed object. When you want to control the offset, then it is a good idea to place an empty game object at the exact same position as the followed object and make that the following object. Then attach the object you actually want to follow as a child of the empty object. That allows you to control the offset by changing the offset between parent and child.

\$\endgroup\$

You must log in to answer this question.

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