Персонаж глобально не поворачивается на точку падения луча

Пытаюсь повернуть персонажа в сторону направления камеры во время движения вперед

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    [SerializeField] private Transform _target;
    [SerializeField] private Vector3 _offset;
    [SerializeField] private float _pitch;
    [SerializeField] private float _sensitivity;
    [SerializeField] private Rigidbody _rigidbody;
    private float _mouseXRotation;
    private float _mouseXRotationCurrent;
    private float _mouseXRotationVelocity;
    private float _smoothTime = 0.1f;
    private void Update()
    {
        _mouseXRotation += Input.GetAxis("Mouse X") * _sensitivity;
        _mouseXRotation = Mathf.Clamp(_mouseXRotation, -130, 130);
        _mouseXRotationCurrent = Mathf.SmoothDamp(_mouseXRotation, _mouseXRotationCurrent, ref _mouseXRotationVelocity, _smoothTime);
        transform.position = _target.position - _offset;
        transform.LookAt(_target.position - Vector3.up * _pitch);
        transform.RotateAround(_target.position, Vector3.up, _mouseXRotationCurrent);
        if (Input.GetKey(KeyCode.W))
        {
            Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100f, 7))
            {
                print(hit.transform.name);
                _target.rotation = Quaternion.LookRotation(hit.point);
            }
        }
    }
}

Ответы (0 шт):