Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

Unity 5.1 FPS Controller Question

jmorris142jmorris142 Posts: 83
edited August 2015 in Unity Development
I have the new VR Supported Mode working now and removed all OVR Prefabs in place of Unity FPS controller, but one strange thing I just noticed.

The OVR FPS controller would use your head forward facing position when you walk or "Sprint" forward so you were moving towards where you were looking. Felt great and correct,

The standard unity FPS controller walks or Sprints but doesn't seem to update to your forward looking position as well, the result is looking forward but moving sideways a lot of the time.

It took me a while to figure out why I was all of a sudden getting major motion sickness feelings on my scenes that felt fine before.

Is there a checkbox somewhere I could use to correct this or am I missing something somewhere?. Thanks

I can provide links to two scenes, one built in 5.0.2 and one in 5.1 if that is helpful.


  • cyberealitycybereality Posts: 26,156 Oculus Staff
    Yes, I noticed this as well. I think the new way actually makes more sense (like turning your head versus turning your body) but it does mean you sometimes end up in a weird off-center angle. Let me see if there is a way to change this.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • jmorris142jmorris142 Posts: 83
    Thank you for looking into this. It totally makes more sense but somehow it doesn't "feel" right. After a few more hours of experimenting, I think it's also that you can never move your mouse or controller as accurately of carefully as you can move your head, so things also feel way smoother with the previous version. Maybe the unity controller just needs the addition of that check box to use head movement, so anyone could choose to go either way.
  • I found a quick fix for this, in FirstPersonContoller.cs.

    Change this line: (line 100)
    Vector3 desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x;
    To this:
    Vector3 desiredMove = m_Camera.transform.forward * m_Input.y + m_Camera.transform.right * m_Input.x;
    Its kind of hacky but it works for simple control :)
  • xhonzixhonzi Posts: 99
    Hiro Protagonist
    Moving your feet with your head is gross.
  • BigBBigB Posts: 6
    I have the same problem.
    I think what the OP says, is that the way to move around our character, should be like in the Oculus demo (Oculus World Demo), we move our head and the direction is updated to face where we are looking at.
    At the moment, we look somewhere and when we walk forward we go to a totally different direction, and this makes everything ackward.
    The only situation I think this should not behave like this, is when we are in the control of a car, we don't want to turn the car with our head, but maybe a checkbox with an option or something ?
  • weasel47weasel47 Posts: 301
    In real life you generally walk in the direction your body is facing, not the direction your head is facing...
  • BigBBigB Posts: 6
    That's in real life, we are are doing games, not simulating real life.
  • jmorris142jmorris142 Posts: 83
    jamiecurrie, that works perfectly thank you! just what I was after.

    BigB, exactly, well said:)
  • jmorris142jmorris142 Posts: 83
    jamiecurrie, been using your fix a lot now, it's great!

    Now I have a more complex issue, that I am not sure if it is a unity thing, a physics engine thing or an oculus thing, but I am sure someone here can figure it out:)

    My game relies on shooting projectiles based off your head position, since you shoot from cannons on your helmet.

    I spawn a projectile prefab with a impuse force on a set axis at a set speed from a spawn point game object attached to my helmet that is also parented to the FPS camera etc. Everything moves perfectly with the head.

    The change to the FPS controller to use your head movement to also change your walking movement direction is perfect, however my next issue is that projectiles spawned from the helmet move only in the direction that the mouse or controller was last pointing and do not seem to be using the rotation of the head even though they are parented and physical moving in 3D space to the correct rotation to spawn from. I hope this make some sense, I am no engineer, so I am sure there is a simple explanation or fix for this.
  • cyberealitycybereality Posts: 26,156 Oculus Staff
    Try using the InputTracking functions to obtain the correct head orientation.

    http://docs.unity3d.com/ScriptReference ... cking.html
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • jmorris142jmorris142 Posts: 83
    Excellent, thank you so much cybereality, I will try that out.
  • jmorris142jmorris142 Posts: 83
    After some more experimenting I found there is what seems to be a bug with 5.1 in regards to spawning anything at the head position / rotation. I can repro this 100% and its a weird one, took a long time to find.

    Unless there are 2 x FPS character controller prefabs in the scene objects spawned won't use the correct head position.

    With just one it's all broken, but add a second one and it's all fine except now framerate is suffering.

    I imagine people know about this and it might be fixed in the next version, just mentioning it in case anyone has the same issues.
  • petereptpeterept Posts: 170 Oculus Start Member
    The solution above doesn't work for me because I have an avatar body attached to my FirstPersonController. So even though the character is moving in the direction of where the player is looking, the character itself remains pointing in the original direction.

    What I did was integrate in the HmdRotatesY feature from OVRPlayerController.

    Make the following changes to FirstPersonController.cs

    1. Insert this public attribute to control the feature:
    public bool HmdRotatesY = true;

    2. Insert this code at the bottom of Start():
    // HmdRotatesY parent object
    			GameObject cameraParent = new GameObject("Camera Parent");
    			cameraParent.transform.SetParent(m_Camera.transform.parent, false);
    			m_Camera.transform.SetParent(cameraParent.transform, false);

    3. Insert this code into the start of RotateView():
    if (HmdRotatesY)
    				Transform root = m_Camera.transform.parent;
    				Transform centerEye = m_Camera.transform;
    				Vector3 prevPos = root.position;
    				Quaternion prevRot = root.rotation;
    				transform.rotation = Quaternion.Euler(0.0f, centerEye.rotation.eulerAngles.y, 0.0f);
    				root.position = prevPos;
    				root.rotation = prevRot;
    				// Reset the mouse look to our new orientation
    				m_MouseLook.Init(transform, m_Camera.transform);
    That's it. Now as with OVR SDK you can turn on/off the HmdRotatesY as needed. And your avatar models will rotate correctly.

    Hope that helps!

    Check out my Unity VR development blog:
  • cyberealitycybereality Posts: 26,156 Oculus Staff
    Thanks for sharing. Very helpful.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • HappySliceHappySlice Posts: 36
    Brain Burst
    I am still experiencing the 0.6.0 problem in Unity 5.1 where the HMD doesn't move the the camera and doesn't goto direct to rift in play mode. So I went back to 5.0.3.

    But I was worried about this, thanks for the code and the API reference. Seems way more straight forward than the old OVR API -- nothing personal Oculus devs, built in integration is just more simple 99% of the time ;)

    Glad to know I can get "swivel-chair mode" working this easy.

    Any word on an ETA on a fix or 0.6.1 update, cybereality? :)
  • cyberealitycybereality Posts: 26,156 Oculus Staff
    @HappySlice: If head-tracking is not working at all, and doesn't go into direct to rift mode, then that sounds like a bug and a totally separate issue from this topic. Please create a new thread with more details (logs, etc. viewtopic.php?f=34&t=23521 ) and I can look into it further.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • JorgensenJorgensen Posts: 12
    thanks for the head forward tip!
    "Vector3 desiredMove = m_Camera.transform.forward * m_Input.y + m_Camera.transform.right * m_Input.x;"

    should be a buildin option :-)
  • VirtualNinjaVirtualNinja Posts: 17
    Thanks for your tips.
    Vector3 desiredMove = m_Camera.transform.forward * m_Input.y + m_Camera.transform.right * m_Input.x;
  • billydwightyijiranbillydwightyijiran Posts: 4
    Thanks for this guys, for those who want the same thing, this lil tweak works like a charm after nights of experiments and trying to figure out! :) Thank you.
    Vector3 desiredMove = m_Camera.transform.forward * m_Input.y + m_Camera.transform.right * m_Input.x;
Sign In or Register to comment.