- Home /
Transform.RotateAround axis calculation
I would like to use function RotateAround (point : Vector3, axis : Vector3, angle : float) : void for orbiting script for simple 3D orbiting :) Can anyone suggest an algorithm for calculation of Transform.RotateAround axis : Vector3 so that the orbital plane passes through the point : Vector3? I find solution for cases where orbital object belongs to the axis but confused when all of its position coordinates != 0.
3D orbiting scripts will be appreciated too :)
What if you make a rig for it?
Have one game object as your center and another at the end point you wish the orbit plane to pass through.
Then point the center object at the end point (`LookAt` can come handy, but only has to do it once so it kind of 'snaps' into place) and rotate it around it's own Y axis (`centerObject.Up` to be more precise).
$$anonymous$$ake the orbiting object a child of the center object or make it follow a child of the center game object (that would need to be positioned at the desired orbit distance away from the center object of course).
If i have several orbiting objects so I need personal GameObject center for each other :) It's not a problem, but may be there is some elegant solution :)
Also I am not sure that the parent-child rig could rotate around the parent object but not around the "center mass" :)
Answer by sgmongo · Feb 09, 2012 at 03:07 PM
Well there are two differing ways I can imagine this working.
The hard way would be to restructure the parent-daughter relationship of the objects and only rotate the parent. That's honestly a cannonball-to-kill-a-fly approach though.
I would suggest using a Quaternion.Euler. Basically setup the pivot location as a quaternion and apply a Eular style change in rotation to the group as a whole.
Something like:
Game object A = Pivot Point 1 Game object B = Pivot Point 2
Both game objects are parented to a master object.
Create a quaternion.eular change based on the positions and apply the results to the master object.
It seems to be the smartest way I can think of, without disrupting your programming too much.
I hope to find solution for RotateAround :) I'm sure that's not a problem :)