Rotate the Planet Earth wherever clicked


I want to add rotate by click to this example.

when user click on earth, the clicked point is exactly in front of the camera

How can Rotate The Earth wherever clicked on earth ?


For something like that you will need to calculate the require rotation to animate the camera to that point on click.

You could use a dummy parent/child entities for that:

  1. Position the parent at the center of the globe.
  2. On click position the child entity on the clicked position on the surface.
  3. Get the rotation of the child entity.
  4. Apply that rotation to the camera, preferably using an animation to smoothly transition to that position.


I have positions of surface and globe !

How can I do number three ? (Get the rotation of the child entity.)

You can use entity.getRotation() or entity.getEulerAngles() to get it, and apply it to your camera. Just note if you apply it at it is then the camera needs to have a similar hierarchy (parent/child entity).