[SOLVED] How to have object orbit

I don’t know how to utilize Math.cos(), and Math.sin() to have an object move in a circular motion. how do I do this?

1 Like

What you can do is:

  1. Create a rotate.js script
  2. Add it to an entity(this will be your parent object)
  3. Add the object that you want to move in a circular motion as a child of the rotating entity
  4. Move the child entity away from the center of the parent object (the distance from the center is the radius of the circular path the child entity will take


The rotate.js script will look something like this. The update script is called every 1/60th of a second. In this case, I’ve decided to rotate the object 3 degrees along the y-axis every time it’s called. You can slow down movement by using smaller numbers and speed up by using larger ones(I would stay under 15 degrees for most purposes because 60fps is pretty fast). You can also change the direction of the rotation by making the rotation angle negative.

Add the script component to the parent entity and select the rotate.js script created.

Right-click on the parent entity and select “New Entity”, then select your entity type(I went with ‘Model’). The entity created by doing this will automatically be added as a child.

Select the mesh to be used for the model (I went with the Box primitive).

Finally, move your object away from the center. Make sure the ‘Translate’ tool is selected (the icon with the four arrows on the far upper left).

Your child object should now be moving in a circular motion when you press ‘Play’ on your scene.

*You can also disable the model for your parent entity so that you can’t see it.

Hope this Helps

1 Like

Thank you! it works fine now. 51%20AM