- Home /
How to rotate an object depending on the rotation of an other Object
Hey guys, actually i´m facing the following problem. i have two components which i want to assembly. i have succsesfully implemented a virtually realty application which needs some improvements. so for example i have two technical components, which only could be assembled in one specific way. in my scenerio i have one main component and some assembly parts. so when im loading an assembly part into my Scene i want it to be in the right angle or assembly direction to my main component. in addition it should rotate as i rotate the main component. so the assemby part should always follow the right assembly position, but it should still stay at his own position. i´ve tried to implement this by using unity´s lookat or rotate function. but i didn´t get good results. maybe one of you has a good idea?
Answer by AconitumNapellum · Jan 16, 2020 at 08:32 AM
Can't you just apply the same rotation to both objects? If you rotate the main component just apply the same exact rotation to the assembly part...
Answer by ro-ca · Jan 16, 2020 at 09:30 AM
Thanks for your answer! I tried: ObjectB.transform.rotation = ObjectA.transform.rotation; The rotation works fine so far, but ObjectB rotates around ObjectA. I want ObjectB to rotate around its own axes. So while i´m rotating ObjectA, ObjectB should rotate as well but not by moving around A. B should not loose its position.
I believe you're looking for transform.localRotation, not transform.rotation. Just a guess, I don't know what your scene looks like.
Thanks again! I tried to use the rotation comment just with two cubes and it worked. So the actual problem I´m facing is that I converted cad files into .fbx, now I noticed that the pivot points of my converted objects are not centered in the middle of them. When I try to rotate my objects, they rotate around their pivot points. Is it possible to move the pivot point? Or to rotate around the center ins$$anonymous$$d of the pivot point? I appreciate your help!
I used to have a similar problem a while ago. I couldn't find a way to change the model pivot but i managed to solve it by parenting the 3d model to an empty gameobject positioned in the middle of the model, and then rotating the empty object ins$$anonymous$$d of the model itself. Hard to explain, hope you understand
Answer by parmardarshanv · Jan 16, 2020 at 12:59 PM
By the details you explained in the comment, for the axis rotation you can implement ObjectB.transform.rotation = ObjectA.transform.rotation. If you want to rotate object A on a circular path around object B, the following video is the exact answer: https://www.youtube.com/watch?v=3PHc6vEckvc
Your answer
Follow this Question
Related Questions
2D look at 1 Answer
NavMesh agent won't rotate around Y axis 0 Answers
Problem with Quaternion.LookRotation() 1 Answer
rotate camera to face a specific object? 1 Answer
Merge a rotation(vector3) to a lookAt(quaternion) ? 1 Answer