Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
cruncher3019's avatar
cruncher3019
Honored Guest
12 years ago

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:

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

7 Replies

Replies have been turned off for this discussion
  • Can I ask why you would limit the rotation? I don't believe this would result in a good user experience.

    Also, the Euler angles swap around at 180 degrees, so you have to do more logic than a simple min/max clamp.
  • It's how I'm being forced to do it. I don't like it, but the job is making me.

    We're making an on-rails simulation type experience and we don't want the player to turn to see his body. But we also don't want the body to move around, so we set restrictions.
  • Well then you must re-design it to allow much more rotating freedom at very least, and by time consumer version is out you must also account for substational head travel as well. Your approach there is like designing a car that only allows 10 degrees of steering wheel rotation.
  • owenwp's avatar
    owenwp
    Expert Protege
    If you really want to prevent the user from looking in some direction, put up a visual barrier. Make it so there is only black behind the player or something similar.

    Actually constraining the look direction will cause sickness, pretty much guaranteed.
  • go with the visual barrier idea for sure. Think of a space suit where you can turn your head inside the helmet, but the helmet itself doesn't turn.
  • I appreciate the info guys. If it's ever up to me I'll find a different way to do it, but for now I need to stick with this method. Thanks again!