- Home /
How to attach components to rigidbodies in editor
I have been reading about hinge joints and I want to use them to attach boxes to random points on a cylinder. How do I "attach" things in the editor? I know how to add components to individual objects, but I don't know how to tie two objects together. I just need the step-by-step guide of the mouse clicks I need to do.
In the picture provided, I want the cubes to stay where they are relative to the cylinder as it moves/rotates. I already have the "LookAtCamera" script which keeps the boxes faces in view. Now I just need to figure out how to build the hinge between these objects.
Edit: The first answer provided was so simple it eluded me...to drag the cubes onto the cylinder in the editor. That locks the two items together during runtime, correct? So do I add hinge components to the little red boxes to let them rotate freely? How do I pick the hinge points? Do I have to provide the numbers or is there a mouse point-n-click operation?
Links to tutorials that build scenes/objects/characters would help out a ton. Thanks!
Answer by OperationDogBird · Aug 05, 2012 at 09:20 PM
All you need to do is drag those objects onto the cylinder object so that they are children of it.
In Hierarchy, click on a 'box' you want to attach, drag onto the cylinder, done.
You dont need LookAt in this case since they are already in the correct rotation.
Simple! That explains why I couldn't find any questions out there already. But now the cylinder and cubes are locked together, as one, right? I edited my question to ask how to finish the hinge-ing operation. Thanks!
Im not sure exactly what you are doing, but from what i can tell you are using this like the lid of a trash can. You can rotate the entire object based on the pivot of the center red box. This will require a couple lines of scripting to alter the rotation of the object along the x axis.
Heres the tasks at hand:
Find the center box object inside the cylinders children (Use Transform.GetChild or Transform.Find)
Create an empty GameObject and place its transform.position at that boxes transform.position, then parent the cylinder to this new GO. This will be the new pivot point.
Rotate the pivot object and all will follow(you can use transform.Rotate)
Your answer
Follow this Question
Related Questions
Unity editor bugging out 4 Answers
Transform component of Inspector panel changes 1 Answer
Component values don't get assigned 0 Answers