I wrote it with the help of a translator.
When I assign my spaceship rotation to the camera, everything is fine. But as soon as I add an offset to rotate the camera, with complex spaceship rotations, the camera goes crazy. I don’t understand Quaternions well enough to do anything with them, I only have a superficial understanding of them. How can I make the camera always have the same rotation as the ship with a given offset?
video : - YouTube
using UnityEngine;
public class FollowCamera : MonoBehaviour
{
public GameObject target;
public Vector3 offset;
public Vector3 offsetRotate;
public Vector3 rotationCamera;
public Vector3 rotationShip;
private void LateUpdate()
{
Vector3 newRotation = target.transform.localRotation.eulerAngles + offsetRotate;
transform.rotation = Quaternion.Euler(newRotation);
transform.position = target.transform.position + (target.transform.rotation * offset);
// данные о повороте камеры и корабля
rotationCamera = transform.rotation.eulerAngles;
rotationShip = target.transform.rotation.eulerAngles;
}
}