Using AddRelativeTorque() keeps the code simple and seems to do away with the physics bug. Also acts more realistic in my opinion by adding a rotational torque force instead of trying to brute-force the objects rotation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
[SerializeField] float mainThrust = 1f;
[SerializeField] float turnTorque = 1f;
Rigidbody rocketRigidbody;
private void Awake()
{
rocketRigidbody = GetComponent<Rigidbody>();
}
void Update()
{
ProcessThrust();
ProcessRoatation();
}
void ProcessThrust()
{
if(Input.GetKey(KeyCode.Space))
{
rocketRigidbody.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
}
}
void ProcessRoatation()
{
if(Input.GetKey(KeyCode.A))
{
ApplyRotation(turnTorque);
}
if (Input.GetKey(KeyCode.D))
{
ApplyRotation(-turnTorque);
}
}
void ApplyRotation(float rotationThisFrame)
{
rocketRigidbody.AddRelativeTorque(Vector3.forward * rotationThisFrame * Time.deltaTime);
}
}