public GameObject turret;
public GameObject camera;
public float rotationSpeed = 10f;
[SerializeField] private Vector3 targetPointInfo;
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
TurretAimPointer aimpainter = camera.GetComponent();
aimpainter.target = targetPointInfo;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(targetPointInfo), rotationSpeed * Time.deltaTime);
//TurretAim();
}
private void TurretAim()
{
//TurretAimPointer aimpainter = camera.GetComponent();
//aimpainter.target = targetPointInfo;
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(targetPointInfo), rotationSpeed * Time.deltaTime);
//Vector3 relativePosition = aimpainter.target - transform.position;
//Quaternion rotation = Quaternion.LookRotation(relativePosition, Vector3.up);
//transform.rotation = rotation;
}
< /code>
} < /p>
{
// Start is called before the first frame update
private Camera cam;
public Vector3 target;
void Start()
{
}
// Update is called once per frame
void Update()
{
TurretAimPaint();
}
public void TurretAimPaint()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(transform.position, Vector3.forward, out hit))
{
target = hit.point;
}
}
< /code>
} < /p>
These two images show the difference in the hit point info of the two scripts


Подробнее здесь: https://stackoverflow.com/questions/796 ... t-an-objec