I have a camera attached to an entity that moves in a circular pattern around a fixed center position. I am attempting to clamp the rotation of the camera such that it can only look inward toward the center of the circle.
I have tried for some time to accomplish this but haven't had much luck.
Simply clamping the angles like this will not work:
rotation = Vector3.Clamp(rotation, new Vector3(-50.0f, rotationY, 40.0f), new Vector3(-20.0f, rotationY, 100.0f));
(the rotation angles are relative to world space, and not the local rotation of the entity)
I need to get a clamp value that is relative to the direction the entity is facing.
Is there any way I can accomplish this?
Update-
Adding the rotation of the entity to the camera rotation like in the following seems to work intermittently, but now it seems the camera starts stuttering at certain points around the circle.
Still stuck.
Vector3 clampMin = new Vector3(-50.0f, 0, 40.0f);
Vector3 clampMax = new Vector3(-20.0f, 0, 100.0f);
public void Update()
{
// adding the users input
rotation = camera.Rotation + (new Vector3(GetInputY(), 0, GetInputX()) * 4.0f);
float clampX = ClampAngle(rotation.X, clampMin.X, clampMax.X);
float clampZ = ClampAngle(rotation.Z,
entity.Rotation.Z + clampMin.Z,
entity.Rotation.Z + clampMax.Z);
camera.Rotation = new Vector3(clampX, 0, clampZ);
}
lerp(lastangle,newangle,0.2)\$\endgroup\$