Restricting Camera Rotation
Hi guys, I've been spending a lot of time trying to integrate into the OVRCamera.cs script functionality to restrict the players head movement if he tries to exceed certain angles of rotation.
I've made some progress (check code below) and now when the character looks left, right, up, or down, he will be forced to stop.
However, I'm having an issue where if you keep rotating the Oculus after he forces the view to stop, eventually you will pop to viewing the other restricted position.
I'm pretty sure it has to do with these two lines and the oculus:
and
If the angle of the Oculus after getting the modulus value ends up dropping below or exceeding 180, depending on when way you are turning the device, it will pop to where you are limited for the opposite view.
I'm looking to see if anyone has ever tried something similar to what I am doing. If you have, do you find my way efficient, or is there an easier way to do this with the Oculus?
Also, if you have an idea on-how to fix the pop, I'd appreciate it.
Code Dump Following:
Mid = 180
Min = 360
overEdge = 6-slot array of bools
I've made some progress (check code below) and now when the character looks left, right, up, or down, he will be forced to stop.
However, I'm having an issue where if you keep rotating the Oculus after he forces the view to stop, eventually you will pop to viewing the other restricted position.
I'm pretty sure it has to do with these two lines and the oculus:
else if ((vals[i] > low && vals[i] < Mid) || overEdge[counter])
and
else if ((vals[i] < high && vals[i] > Mid) || overEdge[counter+1])
If the angle of the Oculus after getting the modulus value ends up dropping below or exceeding 180, depending on when way you are turning the device, it will pop to where you are limited for the opposite view.
I'm looking to see if anyone has ever tried something similar to what I am doing. If you have, do you find my way efficient, or is there an easier way to do this with the Oculus?
Also, if you have an idea on-how to fix the pop, I'd appreciate it.
Code Dump Following:
int counter = 0;
float low = 80.0f, high = 280.0f;
Vector3 eulers = q.eulerAngles;
string parentTag = transform.parent.gameObject.tag;
float[] vals = {eulers.x, eulers.y, eulers.z};
float[] offsetVals = {
offsetOBJ.transform.rotation.eulerAngles.x,
offsetOBJ.transform.rotation.eulerAngles.y,
offsetOBJ.transform.rotation.eulerAngles.z};
if (parentTag == "cameraPilot")
low = 120.0f;
//Get the value of angles based on the offset of the object attached
//Mod each value by 360 to make sure we're always working within 360 degrees
for (int i =0; i < 3; i++)
{
vals[i] -= offsetVals[i];
vals[i] = Mod(vals[i], Max);
}
for (int i =0; i < 3; i++) //Iterate through all three angles
{
//If value is less than 90 or greater than 270, we aren't over/at the edge
if (vals[i] < low)
overEdge[counter] = false;
else if (vals[i] > high)
overEdge[counter+1] = false;
else if ((vals[i] > low && vals[i] < Mid) || overEdge[counter])
{
//Set a value to the proper angle based on what iteration we are on
switch(i)
{
case 0:
eulers.x = Mod(low + offsetVals[i], Max); //Mod the value so we have a value within 360 units
break;
case 1:
eulers.y = Mod(low + offsetVals[i], Max);
break;
case 2:
eulers.z = Mod(low + offsetVals[i], Max);
break;
}
overEdge [counter] = true; //We're over the edge (it's something I said)
}
else if ((vals[i] < high && vals[i] > Mid) || overEdge[counter+1])
{
switch(i)
{
case 0:
eulers.x = Mod(high + offsetVals[i], Max);
break;
case 1:
eulers.y = Mod(high + offsetVals[i], Max);
break;
case 2:
eulers.z = Mod(high + offsetVals[i], Max);
break;
}
overEdge [counter+1] = true;
}
counter += 2; //Move onto our next two edge bools
}
q.eulerAngles = eulers; //Set the remedied angles to the headset.
Mid = 180
Min = 360
overEdge = 6-slot array of bools
