Skip to content

Instantly share code, notes, and snippets.

@rbreve
Last active August 29, 2015 14:06
Show Gist options
  • Save rbreve/e1294661c2054adbcde3 to your computer and use it in GitHub Desktop.
Save rbreve/e1294661c2054adbcde3 to your computer and use it in GitHub Desktop.
Placing objects around a sphere in Unity3D
// sphere radius
float r= 5f;
Vector3 randomPosition = Random.onUnitSphere*r;
GameObject o = Instantiate(item, randomPosition, Quaternion.identity ) as GameObject;
Vector3 up = randomPosition;
Vector3 LookAt = Vector3.Cross(up, -transform.right) + up;
o.transform.LookAt(LookAt, up);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment