Limiting first person camera rotation

Hello, I’m trying to make a first person game with DOTS and I’m having trouble figuring out how to limit the vertical camera rotation so that the player can’t look down into their body or too far in the opposite direction. I have a playerBody entity and a playerHead entity which is a child of the body, and I currently use this line of code to do the rotation using the head’s rotation component as well as a couple of my own components:

rotation.Value = math.mul(rotation.Value, quaternion.RotateX(-inputData.camera.y * sens.value * deltaTime));
It works well, but I’m not sure how to stop it when looking straight down or straight up. Any attempts I’ve made so far to achieve this have not worked as I’d hoped. Any wisdom would be appreciated.

Mathf.clamp is your best bet look up the unity documention and it explains how it works.

You’ll want to have a RotationEulerZXY component on the entity with the camera. The RotatationEulerSystem should automatically set the Rotation based on RotationEulerZXY. Then you can clamp the y component of the RotationEulerZXY. For better performance, use Unity.Mathematics.math.clamp and NOT UnityEngine.Mathf.Clamp

rotationEuler.Value.y += -inputData.camera.y * sens.value * deltaTime;
rotationEuler.Value.y = math.clamp(rotationEuler.Value.y, math.radians(-90), math.radians(90));

Thanks! This works perfectly. The RotationEulerZXY was a very key piece I was missing.