Attaching an object to a controllable rolling ball...

Hey guys,

I’m a newbie to unity and trying to work out how I can create a controllable rolling ball which has another object (like a box) move with it. The box would be placed directly above the ball and turn in the same directon when the ball is moved around. To add to this, the box would react to movement as if it were attached to the centre of the ball; so when the ball moves forward, for example, the box would slightly move back, because it is attached to the pivot point of the ball and is reacting to the forward force. The, when the ball slows down and comes to a hauls, the box then springs back to the centre position above the ball; as it it attached by a spring.

I have been playing with rolling ball demo on the unity page which is cool. Now I just want to see if I can add this box object to it. My initial thought is to create a.n object which is the child of the ball and attach the box to that. Then, add a script to the box to understand the action of the ball. I’m assuming there are various ways to approach this, but I’d love to hear your thoughts on a script/s and where and how to attach these to the given objects.

Thanks in advance for any help.


I hope that this makes sense!

Try using a Spring Joint attached to the box: For instance, you could create an empty GameObject at the desired target height above the ball, set in script to always be at a position above the sphere, with an attached Rigidbody. Then set this empty object as the Connected Rigidbody of the Spring Joint that is attached to the box. You can adjust the Spring to get the desired movement.