Rotate an object around one of his childs in the self space (not the world space)
Hi, I'm Rotating an objet around his Child like that :
transform.RotateAround(transform.GetChild(1).position, Vector3.back, oneSpeed * Time.deltaTime);
But the problem is that the RotateAround function does not have an overload to set the Space to Self (space of the child or the parent, dosn't matter, it's the same) instead of World. I tried with RotateAroundLocal but I'm forced to set the point around which it rotates outside the function, like that :
transform.GetChild(1).RotateAroundLocal(Vector3.back, oneSpeed * Time.deltaTime, Space.Self);
And it only rotates the child, and not the parent. Same tries with the Rotate function, it's the same (RotateAroundLocal is deprecated)
Do you have an idea how I could do that ? I'm a bit in trouble, i just realised 2 days before i have to present the work that it rotated in the world space...and have only until thursday to make this work. Any help woul'd be appreciated.
For starters, you're not doing any favors by asking a community for help and then making up your own terms for things. Local and World spaces are the agreed-upon terms.
To your question, what difference does it make? Of course rotate works in world space. Can you draw a picture?
What do you mean? I don't see what is wrong in my message :x The parent posses two childs (the two groups of cubes). The RotateAround rotates around one of the two groups, in the world axis like here: http://i.imgur.com/O40No4I.png And i wan't it to do that in the Self(/local) axis, like that (the axis of the parent and the child are the same): http://i.imgur.com/t7clSCO.png I tried to display the pictures directly but it don't work :(For starters, you're not doing any favors by asking a community for help and then making up your own terms for things.
Ok good pictures, so you're rotating around some kind of roller coaster tracks? Do you know the coordinates of the track at that point? How are you moving the objects along the track?
Answer by capu087 · Mar 17, 2016 at 03:40 PM
Seem to work like that :
Vector3 pos = transform.GetChild(0).position;
transform.Rotate(Vector3.back, 5, Space.Self);
pos -= transform.GetChild(0).position;
transform.position += pos;
Answer by 5c4r3cr0w · Mar 16, 2016 at 10:06 AM
Try this:
Transform t;
Vector3 v;
float oneSpeed = 50;
void Start(){
t = transform.GetChild(1);
v = transform.InverseTransformPoint(Vector3.back);
}
void Update ()
{
transform.RotateAround(t.position,v, oneSpeed * Time.deltaTime);
}
Thanks for the answer! Unfortunately it doesn't work :( It stills rotate around the z world axis. I tried a lot of things close to your solution, but none seems to work
I also tried
transform.RotateAround(t.localPosition,Vector3.back, oneSpeed * Time.deltaTime);
but it rotates around far away, maybe the point 0,0,0.