# working with RotateArround

I have one cube in some point (x,y,z);

I would like to put Sphere -s into its nodes.

This script I connect with Cube.

public class HandsOnCube : MonoBehaviour
{

``````	// Use this for initialization
private GameObject[] PNodes;
private Vector3[] pos;
private Vector3 offset;
private Quaternion offrot;

void Start ()
{
offrot = transform.rotation;
offset = transform.position - transform.localScale / 2;

pos = new[] {
new Vector3 (0f, 0f, 0f),
new Vector3 (0f, 0f, 1f),
new Vector3 (0f, 1f, 0f),
new Vector3 (0f, 1f, 1f),
new Vector3 (1f, 0f, 0f),
new Vector3 (1f, 0f, 1f),
new Vector3 (1f, 1f, 0f),
new Vector3 (1f, 1f, 1f)
};

int[] inds = new [] {0,1,2,3,4,5,6,7};

PNodes = new GameObject[8];

foreach (int i in inds) {
PNodes  *= new GameObject ();*
``````

_ PNodes = GameObject.CreatePrimitive (PrimitiveType.Sphere);_
PNodes .transform.position = pos + offset + offset_def;
_ PNodes .transform.localScale = new Vector3 (0.2f, 0.2f, 0.2f);_

_ //PNodes .transform.RotateAround = offrot;
RotateGameObjArround (PNodes , transform.position, offrot);
PNodes .SetActive (true);
* }*_

* }*
* void RotateGameObjArround (GameObject o, Vector3 aP, Quaternion Q)*
* { // ap - ArroundPoint*
* Vector3 angles = Q.eulerAngles;*
* o.transform.RotateAround (aP, new Vector3 (1f, 0, 0), angles.x);*
* o.transform.RotateAround (aP, new Vector3 (0, 1f, 0), angles.y);*
* o.transform.RotateAround (aP, new Vector3 (0, 0, 1f), angles.z);*
* }*

* // Update is called once per frame*
* void Update ()*
* {}*
}
Poblem: if Cube rotation = (10,20,30) then Spheres are not situated in right positions. I think that I have to modify RotateGameObjArround fn, but how? Any ideas?

The axis are wrong the axis must be local and it has to be a normal , you can get it by doing cross product .

Hi, if I understand well: you want to create objects at the positions of the vertices of the cube.

The Transform component can transform positions or rotations from the object’s space to the world space. In your case: the pos table represent the local positions of the vertices of the cube. But in world space, those local position has other coordinates that depends on where the cube is positioned + it’s scale & rotation.

[Transform.TransformPoint][1] can transform those local coordinates to world coordinates: it will use the position + rotation + scale of the transform component to do so. Here, just use

``````positionOfTheSphere = transform.TransformPoint( pos *);*
``````

Then you can setup the scale and rotation of the sphere to anything you want.
[1]: Unity - Scripting API: Transform.TransformPoint