- Home /
Spinning Ball on a string problem (slings, trebuchets etc.)
So I have two objects, parent and child. The parent is spinning using transform.rotate. The child rotates around the parent as the parent rotates because thats how their relationship works. I generalize this idea as like that of a ball on a string. you twirl the string in your hand and the ball spins around it.
If I cut the string (ball.transform.parent = null) my knowledge of physics 101 tells me the ball should continue in a straight line tangential to the rotation. When I attempt this in unity the ball sits perfectly still. It just stops the moment I de-parent it. I throw in some variables and watch the inspector and sure enough, both velocity and angular velocity of the ball while it is a child of the string's anchor = (0,0,0). So what gives? how do I find the world velocity of an object rotating around it's parent? If I could find that I could record that each frame and when I de-parent look up the most recent velocity and just keep using that.
Transform.rotate has nothing to do with physics. Your 'ball on a string' analogy isn't really correct, and thinking about it that way can be misleading. If you want it to use physics, use rigidbodies and joints.
Answer by Berenger · Jan 28, 2012 at 12:03 AM
As syclamoth is saying, you should use the unity physics scripts like joints. But if you really want to use Rotate, then you need to calculate eache frame the vector v = pos - lastPos, so when string breaks, metaphorically speaking, you can use rigidbody.AddForce( v * someVariable ).
PS : syclamoth, why you never answer in the answer area, it leaves misleading unanswered questions ! I'm sure you're doing this on purpose to trap people :p
Answer by MidgardSerpent · Jan 28, 2012 at 12:25 AM
Reiterating (and hopefully clarifying) what's been said before.
Parenting an object doesn't create a physics connection... it just keeps the two objects in the same relative positions by changing their transforms.
The best way to do this is to make sure both objects have rigid bodies, then use a fixed joint to represent the "string" ...
Your answer
Follow this Question
Related Questions
Why is a child object not rotating properly with parent? 1 Answer
Why do grouped Terrain objects move together but don't rotate as one? 1 Answer
children doesn't take parent's rotation, position or scale. 1 Answer
Having difficulty with Parent Object rotation and Child Object movement. 0 Answers
Relative transforms and parenting 1 Answer