- Home /
How do I apply rotations to parent child using Rigidbody?
I have a finger object. It is just three cubes representing the finger parts. The 2nd cube is the child of the 1st one. And the 3rd cube is the child of the 2nd one.
This is the heirarchy: Cube1 -> Cube2 -> Cube3
My goal is to apply a rotation angle to the first cube and let the other cubes do the same locally.
Example: Apply 30 degrees Z rotation to the first cube, 30 degrees Z rotation to the 2nd cube, and also the 3rd one. This will make a finger that look like this:
(Forgive me if it doesn't look like a finger) In every Update() frame, I will change the angle (it's just one number) and it will rotate every cube for me.
My question is:
How do I make all these cubes collide properly with other objects?
I tried putting the Rigidbody on all of them and set isKinematic=false because I want to transform them myself. But I still cannot use transform.rotation
to update my rotation because it will miss the collision with a ball very easily (especially the tip of the finger because it moves faster than other parts). Continuous detection doesn't help.
So I tried using rigidbody.MoveRotation()
and rigidbody.MovePosition()
instead, which is a pain because they need absolute values. They worked but the animation is so jumpy when I change the angle quickly. I'm guessing that the animation is jumpy because there are many Rigidbodies or because the physics engine cannot interpolate the position of each box properly when I use MoveRotation()
and MovePosition()
.
I need to use MovePosition()
also because when I use only child.MoveRotation(transform.parent.rotation * originalChildLocalRotation * Quaternion.Euler(0, 0, angle))
, the position doesn't move relative to the parent. So I have to compute child.MovePosition(parent.TransformPoint(originalLocalPositionOfTheChild))
every frame too.
Your answer
Follow this Question
Related Questions
Vector3.Slerp normal 1 Answer
Solved | Rotating Object in Single Axis while staying Perpendicular to a Rotating Plane 1 Answer
When creating joints during game play how do you change the position and rotation of an object. 0 Answers
How can I multiply the rotation of a mirrored object? 1 Answer
Rotating 2D sprite to match surface. 0 Answers