Я работаю над Unity 2022.3.37 и, как я уже сказал в названии, я хочу, чтобы игровой объект вращался (только по вертикальной оси) в направлении моего вектора3.
Допустим, у вас есть пистолет , вы снимаете на стене, точка съемки представляет собой вектор3, а на земле есть компас, который вращается в направлении точки съемки.
Как я мог это сделать?
i пробовал что-то подобное, но оно вращается по оси Z
// Calculate the direction from the compass to the shoot point
Vector3 direction = shootPoint - compass.transform.position;
// Ignore the Y component to rotate only on the vertical axis
direction.y = 0;
// Check if the direction is not zero to avoid errors
if (direction != Vector3.zero)
{
// Calculate the target rotation to point towards the shootPoint
Quaternion targetRotation = Quaternion.LookRotation(direction);
// Apply the target rotation, keeping the rotation constrained to the Y-axis
compass.transform.rotation = Quaternion.Euler(90, targetRotation.eulerAngles.y, 0);
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... rd-vector3
Unity С# Как повернуть игровой объект по горизонтальной оси в направлении Vector3 ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение