Как вращать глобус, чтобы при выборе позиции на глобусе с помощью щелчка мышью на нем не наклонять глобус вбок? - PullRequest
1 голос
/ 27 января 2020

Я достиг глобуса, вращающегося по щелчку мыши на любой конкретной панели на глобусе, и положение панели при щелчке перемещается в центр камеры, но проблема в том, что глобус перемещается на кратчайшее расстояние между двумя точками (центр камеры и следующая позиция) на глобусе).

Согласно изображению, в настоящее время глобус переходит на следующую позицию и наклоняется следующим образом

Согласно этому изображению I нужно, чтобы глобус привел к такому повороту, когда северное поле и южное поле остаются на своей стороне и смотрят в камеру.

public List<GameObject> characters = new List<GameObject>();
private Quaternion targetRotation = Quaternion.identity;

public void CharacterPosition(int charNum)
{
    Quaternion diff = Quaternion.FromToRotation(characters[charNum].transform.up, camera.transform.position - transform.position);
    targetRotation = diff * transform.rotation;
    transform.DORotateQuaternion(targetRotation, 1f);
    hitAgainNumber = charNum;
}

"символы" Список состоит из панели на земном шаре на нескольких позициях. Плагин DoTween используется для вращения.

Я буду очень благодарен, если кто-нибудь поможет мне с этим.

1 Ответ

1 голос
/ 27 января 2020

Пояснения в комментариях:

public List<GameObject> characters = new List<GameObject>();
private Quaternion targetRotation = Quaternion.identity;

public void CharacterPosition(int charNum)
{      
    // Use cross products to find the closest vector to Vector3.up which is orthogonal
    // to the direction from the sphere to the camera. 
    // This direction is to be the sprite's forward after we rotate the sphere
    Vector3 charGoalUp = camera.transform.position - transform.position;
    Vector3 charGoalRight = Vector3.Cross(charGoalUp, Vector3.up);
    Vector3 charGoalForward = Vector3.Cross(charGoalRight, charGoalUp);

    // Get the goal rotation for the character using `LookRotation`:
    Quaternion charGoalRotation = Quaternion.LookRotation(charGoalForward, charGoalUp);

    // Determine the world rotation that needs to apply to the character:
    // delta * char_start = char_end -> delta = char_end * inv(char_start)
    Quaternion worldCharDelta = charGoalRotation 
            * Quaternion.Inverse(characters[charNum].transform.rotation);

    // Apply that same world rotation to the globe:
    targetRotation = worldCharDelta * transform.rotation;

    transform.DORotateQuaternion(targetRotation, 1f);
    hitAgainNumber = charNum;

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...