Possibly related to gimbal lock, but I don’t see rotation code above.
Generally, some notes on clamping rotation and NOT using .eulerAngles because of gimbal lock: