- Home /
problem with the rotation of an object
Let me describe the project first. We intent to create a program that loads molecules (in a simplified way) from a xml file.
The rpoblem lies that after creating the first atom, the second atom needs to be rotated AROUND the first. But, this sounds easier than it is, as RotateAround happens on the world axis. The problem is multiplied by the fact that each object (after it's rotated), creates more objects (attached to itself), that all need to be rotated in a similar way. The scripts that handle the rotations are: -scr_generate, this generates the ' balls' -scr_mono, generates 1 child object -scr_duo, generates 2 child objects -scr_trio, generates 3 child objects -scr_tetra, generates 2 child objects
In the link provided, the (nearly whole) project is there, after starting the following functions can be used to manipulate the camera and the view: left mouse rotates the molecule, right mouse moves the camera, the scroll wheel, surprisingly, zooms in and out. The menu on the left is sorted in the following order: hide menu, create molecule (not working (yet)), load molecule, information (in dutch), take screenshot, and quit.
The questions comes down to: How do we rotate objects around another object (parent) using the parent's local xyz axis?
If we should provide more (or less) information on something, please ask us.
We thank you in advance,
Here's the link: https://www.dropbox.com/s/juqahamn320gciu/unity.rar
You could create prefabs of the atoms, with the atom itself linked to a connection point somewhere along one of its axis and then instantiate it at the atoms position,rotation. Link it and then have full control of its rotation in its localrotation? Very simple solution, probably not what you want :P
How would you suggest we find out where the position of the atom should be? Because currently, we are letting RotateAround handle that. I thought about prefabs before, but I couldn't figure out how to do the positioning. The atom is simple primitive sphere, while it's childeren are cylinders.
Oh, and I forogt to say, I'm the other part of the 'we' he mentions.
Answer by Wolfram · Feb 03, 2013 at 04:31 PM
You should be fine by using the parent's local coordinate axes, instead of the the world space axes, i.e., obj.transform.right instead of Vector3.right, and so on:
attach1.transform.RotateAround(obj.transform.position,obj.transform.right,0);//x
I suggest doing a tutorial about Transform hierarchies and local coordinates, it should help your understanding of these situations.