Очень странное поведение башни танка в Unity 3D
У меня есть танк с отдельным кодом для башни:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TowerScript : MonoBehaviour
{
public GameObject player;
public void LookAtXZ(Vector3 point, float speed)
{
var direction = (point - transform.position).normalized;
direction.y = 0f;
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(direction), speed);
}
void Start()
{
player = GameObject.Find("Player");
}
void Update()
{
LookAtXZ(player.transform.position, 0.3f);
}
}
Этот код должен поворачивать башню за игроком. И он в принципе работает. Но почему-то башня дополнительно поворачивается вверх:

Как это исправить?
UPD: Попробовал использовать: transform.LookAt(player.transform.position);. Ничего не изменилось.
Ответы (1 шт):
Автор решения: ProstoBob
→ Ссылка
Нашел работающий код:
using UnityEngine;
public class TowerScript : MonoBehaviour
{
[SerializeField] Transform player;
[SerializeField] Vector3 auxRotation = new Vector3( -90 , 0 , 0 );
void Update ()
{
transform.LookAt(player.position );
transform.rotation *= Quaternion.Euler(auxRotation);
}
}