# Translate in 3D space by fixed distance

Since I don’t get very much about Quaternion and Euler, but I suppose I should, I’m asking how to translate several objects from a particular center point, maintaining the same distance but in different positions in 3D space.

I can achieve the same concept in 2D with trigonometry, given an angle I can get the x and y value.

How to get x, y, z from a given distance and ‘angle’?

Hey fabiof,

You’re saying that you want the objects to move from a center, maintaining the same distance. That sounds like a Sphere to me

Unity has a neat function that will give you a random point on a sphere, called Random.onUnitSphere. You can use that, or you can roll your own, if you wanted to have more control over which direction the objects moved. Attached is a Unity scene file that demonstrates both ways of doing this. When you run the scene, hit the up arrow to see the Random.onUnitSphere in action, and down arrow to see it done the other way. They should both look identical.

Look at the code in the Movein3D script file to figure out what’s going on. It’s pretty easy.

I hope this helps.

-Yilmaz

122663–4608–\$3dmovetest_152.zip (512 KB)

OK, Got it by a quick google search. Just a math issue
here my snippet, maybe useful to someone…

``````function Start()
{
var phi : float = Random.value*Mathf.PI;
var theta : float = Random.value*(2*Mathf.PI);

var raggio : float = 10;

var cx : float = raggio*Mathf.Cos(theta)*Mathf.Sin(phi);
var cy : float = raggio*Mathf.Sin(theta)*Mathf.Sin(phi);
var cz : float = raggio*Mathf.Cos(phi);

transform.Translate(Vector3(cx,cy,cz));
}
``````

Ops, we did submit at the same time!
oh thank you, I’m just looking for a built-in Unity function to do that before to found out a generic snippet around the web.
And yes, the title should be ‘distribuiting object around a sphere’
ok, I’ll take a look to your file.

Fabio