Hello. I will try to be very explicit about what I’m trying to do.
So. I have a sphere which is a (globe). This sphere has territories on it ( Imgur: The magic of the Internet )
When I click on that territory, I’m looking to rotate the sphere so the territory will be in front of camera like this ( https://imgur.com/00vSu33 )
I have something like this in hierarchy:
Globe (Gameobject parent which has some scripts like tap on territories or swipe the globe)
- GlobeModel
- Territory1
- Territory2
- etc
EDIT : Realized LookRotation might not work, and tested a different solution with a tested piece of code.
You can use Quaternion.FromToRotation. Here’s a tested piece of code that does what you want using a raycast to get a normal on the sphere. You can use your continent’s position from the sphere to get that normal.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Globe : MonoBehaviour
{
public float slerpMultiplier = 2.0f;
private new Camera camera = null;
private Quaternion targetRotation = Quaternion.identity;
private void Awake()
{
camera = Camera.main;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Quaternion diff = Quaternion.FromToRotation(hit.normal, camera.transform.position - transform.position);
targetRotation = diff * transform.rotation;
}
}
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * slerpMultiplier);
}
}
EDIT : Here’s the vector you need to compute, and the two informations you’ll need for that. The continent is simulated by a cube here.