So after gathering info from people and experimenting and reading i am standing to a point where i can’t finish my main task which seems relatively simple, but in fact it’s a total nightmare.
So i am working with my friend who wants a rotating globe with two rotation functionalities.
- When a player swipes with the finger or moves the mouse in some direction the globe needs to rotate to that direction with some force - smoothly.
- When the player only clicks or taps ones over the globe, the globe must rotate so the clicked point faces the center of the camera.
So here i go.For the first functionality i added rigidbody to the globe and started rotating the globe adding torque in direction towards the swiped position.Then just clamped the Y axis to a certain angle so it wont flip the globe around.Pretty easy and it works OK.
For the second functionality what i did is get the tapped or clicked point from the globe and create a rotation from it to Vector3.forward which stands in my scene as the camera’s center.Now here is where i found out that when i rotate the globe arbitrary like that at certain point the continents started tilting which does not look appealing and it’s not acceptable for the project.Look at the picture:
Next thing i found out is how to rotate the globe by latitude and longitude which was exactly the thing i was looking for and replaced the last method with this one. So now when the player taps over that location it angles the globe to align perfectly to the camera’s center or the world forward vector.Great!
Then i created a method which gets my current latitude and longitude from the center of the globe so even if i spin the globe with torque i will always know the current latitude and longitude from the globes center and i will interpolate the angles without any problems.Now here is where i got it wrong.
When spinning the globe with torque of course, it does not angle the globe by the lat/lon angles.Here when the player spins the globe with the first functionality and after that taps over the planet the interpolation starts with the correct lat/lon, but it seems that this is not enough to get the correct current rotation.The result goes like:
- Globe rotates instantly from the
tilted angle from the torque to the
correct lat/lon angles(bad) - After that it interpolates from
that rotation to the tapped one.(its ok)
Look at the video to see exactly how the rotation happens.I first swipe then i click on a location.
Is it possible to combine the two functionalities:
rotate the rigid body with torque + rotate to latitude/longitude to work together with no conflicts between them and interpolating smoothly?If so how?If not is there any similar way to produce such a thing?