- Home /
How can I move an object along with another object?
I am new at 3d programming I have a scene that contains two object:
A kinematic cube attached to a script that will moving back and forth according to Z-axis
A cylinder with mesh collider on top of the cube
Both of them have a rigid body with gravity.
However, the cylinder is not moving along with the cube, I have no idea how to make it move along with the cube Can anybody five me some tips? Thank you!
Updated: I would like to have the effect just similar to the game "Coin Dozer", where adding a cylinder on the moving platform will make it move along with the cube, and may drop down from the cube and push by it.
Answer by rutter · Oct 11, 2012 at 09:52 AM
It sounds like you want the two objects to move together, as one single object? If so, you might want to try a setup like this:
Parent object contains rigidbody and collider
Child object for the cube renderer
Child object for the cylinder renderer
You can set up parent-child relationships by dragging objects onto each other in the scene hierarchy. When a parent moves, its children move with it.
Apologies if that's not the sort of setup you're looking for.
Thanks for the reply, but I am not looking for this. I would like to have one just like the Coin Dozer game, a coin on a moving platform, but I have no idea how to move the "coin" on the cube.
Answer by always_beta · Oct 11, 2012 at 09:53 AM
You should add the cylinder as a child game object of the cube, and remove rigidbody component from the cylinder.
Would there be a way to do this if your object being the child had a rigidbody?
Answer by dsmurl · Feb 14, 2017 at 06:35 AM
Children ridgid bodies must also be Kinematic if they are expected to be "attached" to something up the parent chain. Check IsKinematic on them and they will stick to another ridgid body.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082201im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move an object to a height 1 Answer
move object back and forth with joystick input 0 Answers