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.

Rich

I hope that this makes sense!

1 Answer

1

Try using a Spring Joint attached to the box: http://docs.unity3d.com/Documentation/Manual/Physics.html. 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.

Thanks. I will give this a go. Much appreciated.

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base. Here at Unity Answers, Answer means Solution, not Response. Please watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers I have converted this to a comment for you. Also you don't have to wait for a moderator to approve a comment.

My fault. Sorry. So, just trying to work this out: '...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...' How is this done exactly. I was assuming you make the empty gameobject the child of the ball, but that's not working. Thanks in advance.

That's ace. Thanks a bunch. I have a couple of other questions if you could be so kind: I want the object that is targeting the ball to follow the direction of ball (turn it's face to the direction the ball) Can the object have a spring motion to give the impression that it it is seemingly attached with a tight spring? So when it jumps for example, the attached object has a little bounce to it? Again thanks in advance.

Sorry, I was just going off your comment in my email, and didn't really read the question or the answer. You may want to use a spring joint. Or ... if you import the standard scripts that come with Unity (Assets > Import Package > Scripts ), there is a script called SmoothFollow , you should import it and play around with it a bit. Start there and see what you think, then let us know how you found it.