RotateAround or Follow Torus Path.

  1. What is the best method of rotate child object around a parent object regardless of its size? Each time I resize the child object the distance to the parent is different. I make the child smaller its closer to the parent and sometimes inside, I make the child larger its way off in the distance where you can barely see it. Models I use is Planet and its satellite. Not all Satellites are the same size.

  2. I was thinking of drawing a thin torus around a Planet and having the Satellite follow it. So, the next question would be how would you have an object follow the torus? Each planet will have 9 orbit paths using torus, if this method works I don’t have to worry about the Satellite being somewhere else when I resize it. Like the Earth Satellite named Moon that uses the torus path #3, then Mars Phobos #2 and Deimos #5 for example.

  3. So if there is no answer for question 1, question 2 would be the best choice, I just need to know then how to have an object follow in the center of the torus along the path. The rest I can do myself.

Reading through your statements, I’m still fuzzy about many aspects of your setup, but I’m going to give you a script to play with. It solves the problem you state in your question, but with some many open questions about your real needs, it is likely I will miss the mark some.

This script is attached to a moon. You will need to set the following values in the inspector once it is attached:

  • Target - Drag and drop the planet the moon rotates around in the inspector on this variable.
  • Altitude - This is the real world distance between the surface of the planet and the surface of the moon.
  • Speed - How fast the moon rotates around the planet in degrees per second.
  • Axis - The Axis to rotate around. For example if you set this to Vector3.up (0,1,0), the planet would rotate around the equator. A setting of (0,0,1) would be a polar rotation.

There one variable that must be set in the script: ratio. When you moon and planets have scale of (1,1,1), what is their radius in world units? For example, the built in sphere has a radius of 0.5 when the sphere is sized to (1,1,1). Since I don’t know how you modeled your planets/moons, I left this as a variable.

You can reverse the direction of rotation by either by reversing the axis used for rotation or by negating the ‘speed’ variable.

The behaviors of this script are:

  • The moon will follow the planet even if it moves.
  • The moon ignores any planetary rotation
  • The altitude will remain the same no matter what size the planet or moon.
  • The moon is not a child of the planet

Even if this script is somewhat off the mark, I encourage you to play with it using a new scene and some spheres to get the sense of the solution

#pragma strict

var target : Transform;
var altitude = 4.0;
var speed = 20.0;       // Degrees per second
var axis = Vector3.up;

private var ratio = 0.5;  // width to radius ratio
private var v3 : Vector3;
private var center : Transform;

function Start () {
	var arb : Vector3;
	if (axis == Vector3.forward)
		arb = Vector3.right;
		arb = Vector3.forward;
	v3 = Vector3.Cross(axis, arb).normalized;
	v3 = v3 * (target.localScale.x * ratio + transform.localScale.x * ratio + altitude); 
	center = new GameObject().transform;
	transform.parent = center;
	transform.localPosition = v3;

function Update () {
	center.position = target.position;
	center.transform.rotation = Quaternion.AngleAxis(speed * Time.deltaTime, axis) * center.transform.rotation;