How to line up torus with disc?

I have a disc that I position on a sphere, and I’m able to orient it to face out correctly by using the lookAt function.

Now I want to place a torus around it, for use with an animation effect. I originally thought parenting the torus to the disc would rotate it the same way, and it hasn’t worked out like I expected.

I have a way of working for now, where I don’t parent, and I rotate the X and it seems to work. However, I feel like there’s a simpler, more trustworthy way to achieve what I’m looking for.

https://playground.babylonjs.com/#44AJQ5

PG starts out in “first attempt, not working” mode. then there are two booleans to show my other attempts.

(lines 64 and 72).

In my app, i move from the sphere to a projected flat plane, and I need to position the torus correctly there as well. I am able to keep the disc oriented with the lookAt command, but I don’t know if rotating around X is the way to go when this happens.

i’d prefer to somehow use the Parent to help me orient it the torus in the correction direction.

Any suggestions?

thanks

Hi @Keeger

Can you give a link to your PG? I’ll take a look

boy i feel dumb. i thought i had put it in!

https://playground.babylonjs.com/#44AJQ5

when the parenting is set, any change on orientation/position/scaling is also applied to the children. So, you have to build the couple disc/torus before adding any change like the lookat.
That’s what I did in this PR:

https://playground.babylonjs.com/#44AJQ5#3

I also added a rotation on X axis for the torus so the torus is around the disc (line 36). And then, you can apply any change on the disc and the torus will follow.

1 Like

Oh i feel dumb.

I never tried setting the torus rotation before assigning parent. I saw that when I assigned the parent to the torus, it changed the rotation and the position, so I assumed it would do what it does for position: override it.

Didn’t realize it would add to it and basically proportionately maintain the rotation.

Cedric, big thanks. I spent so many hours and the answer was simple! I knew there was a way to make it work with parent, cuz i’m moving the parent around and just want the animation go stay with it.

Woot!.

1 Like

in case you are curious, I was able to set a cone on to the disc, make the disc parent for everything, and keep stuff lined up just using disc. pretty happy!

https://playground.babylonjs.com/#44AJQ5#4

1 Like