[SOLVED] How can I rotate the children around the parent?

Hello, how can I rotate the “shield” object under “Sphere” around “Sphere”?

I’m sure it’s very simple but I’m not sure how the required algorithm or related functions should be. Thank you in advance for your help.

Sample project

Hi @Onur_Ozturk ,

You could just put an empty entity in the same location as the Sphere (even a child of the Sphere if you want) and have the shield be it’s child. That way you could rotate the empty entity and the shield will orbit around the sphere.

1 Like

Hello,

This is the sample project, what I want to ask is how should I write a code to rotate the “shield” object around the “Sphere” object.

I understand the question. The easiest way would be to just use and empty parent. Here a fork of your project:

https://playcanvas.com/editor/scene/1310392

In this case all you have to do is rotate ‘Empty Entity’ and the shield will orbit the Sphere. You won’t need any special coding since the parent empty object’s pivot point is in the same place as the sphere.

I understand what you mean. But I need to do this with code. Because I want it to be like animation. Even if the “Sphere” isn’t moving, I need that shield to spin around. For this reason I need to make the function in code and the “shield” object needs to rotate at a constant speed. Think of it like the animation of the shield that protects a player from incoming attacks in any game. The axis of rotation will be fixed

I have updated my scene with a small script to automatically rotate the entity every frame. The shield now orbit’s the sphere without the sphere moving. You will see that it disappears as it goes around, this is because you are using an element for the shield. You may want to change that to be a plane with a material wit the shield as a texture instead.

2 Likes

Thank you. This is what I was looking for :pray: