Forum Discussion
Itsinthemind
10 years agoExpert Protege
OVR Player Controller issues
I am developing a game using Unity 3D and am trying to get my Oculus Rift Player controller to mount a moving platform, but the platform moves without him when mounted, leaving my OVR player behind. It works perfectly with the Unity Player controller. Does anybody have a suggestion of what I need to do to make it work with the Oculus controller?
16 Replies
- fantasticdevProtegeI was having the same issue with a rising platform whereby the player sometimes either wasn't pushed up or fell through part way up.
I have used two workarounds which are still causing issues some of the time but that is more due to my specific intention.
1. I have a collider trigger on the platform that initialises the animation and a script that makes the platform the player's parent. When the animation finishes, the player's original parent is returned (currently null). I also have a script triggered which stops the player's ability to move by modifying their acceleration, so they can still look around.
This works if you move into the trigger, however, I want the lift animation to be the first thing that happens to the player as I have a section explaining movement after this event.
2. If your platform is animated, enabled 'animate physics'. This might result in the player bobbing as it moves and may still result in them clipping through. - cyberealityGrand ChampionYou should use the standard Unity first person controller, and just replace the camera with the Oculus one.
- So import the Character Controller assets into your project.
- Drag the First Person Controller into the scene.
- Drag the Forward Direction and OVRCameraRig from the OVRPlayerController and put them inside the new First Person Controller.
- Delete Main Camera from the First Person Controller.
- Delete Graphics from Fire Person Controller.
- Set the OVRCameraRig to position all 0 and rotation all 0.
- Disable OVRPlayerController.
Now moving platforms and elevators should work as normal. And you can jump!
Only problem is that the controller no longer adjusts the movement orientation when you turn your head. I will try to find a fix for it tomorrow, it shouldn't be that hard. - cyberealityGrand ChampionOK, after spending way too long tweaking things I finally figured out how to make it work.
To get the rotation of the First Person Controller to account for the Rift, add the following in FPSInputController.js.
At the top of the file, add:public var centerEye : GameObject;
Around line 31, add:var combinedRotation : Quaternion = transform.rotation;
combinedRotation *= Quaternion.Euler(0, centerEye.transform.localEulerAngles.y, 0);
Then edit the next line like this:motor.inputMoveDirection = combinedRotation * directionVector;
Then make sure to link the CenterEyeAnchor into the centerEye variable in the inspector.
That should be it. - ItsinthemindExpert Protege
- cyberealityGrand ChampionYou should be able to click the gear looking icon on the right side of the inspector next to the script and choose 'Edit Script'. Or you can manually open the file in MonoDevelop. It seems like you are trying to open the file with Windows, and Windows by default tried to execute a javascript file (which is a silly thing to default to, but that's another story). You can also reassign the "open with..." action in Windows so it opens in MonoDevelop or a simple code editor like Programmer's Notepad.
- ItsinthemindExpert ProtegeThanks Cyberreality,I have followed all your steps, but sadly my character is not moving. Could be because I messed up the script, or could be because I wasn't quite sure how to implement what you mentioned in your last sentence:
>> Then make sure to link the CenterEyeAnchor into the centerEye variable in the inspector. <<
The ability for my character to jump onto moving objects is the final bit of the puzzle, but also the key thing that makes it into a game. I could just be minutes away if I could get this to work. :) - cyberealityGrand ChampionInside the OVRCameraRig object (on the far left of the screen) are a few other objects, including CenterEyeAnchor. All you have to do is drag that object (CenterEyeAnchor) onto the space in the inspector for FPSInputController (on the far right) in the variable that says "CenterEye". If you do it correctly, you will see it says "CenterEyeAnchor" in the box.
- paulLubosHonored Guest
"cybereality" wrote:
OK, after spending way too long tweaking things I finally figured out how to make it work.
To get the rotation of the First Person Controller to account for the Rift, add the following in FPSInputController.js.
At the top of the file, add:public var centerEye : GameObject;
Around line 31, add:var combinedRotation : Quaternion = transform.rotation;
combinedRotation *= Quaternion.Euler(0, centerEye.transform.localEulerAngles.y, 0);
Then edit the next line like this:motor.inputMoveDirection = combinedRotation * directionVector;
Then make sure to link the CenterEyeAnchor into the centerEye variable in the inspector.
That should be it.
For Unity 5 the scripts are C# based.
Kinda the same drill works though:
[SerializeField] private GameObject centerEye; // add
[SerializeField] private Camera m_Camera; // add serialization
// ...
// remove the m_Camera = Camera.Main part from Start();
// ...
private void FixedUpdate()
{
float speed;
GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height/2f);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
/// Cyber's code here:
Quaternion combinedRotation = transform.rotation;
combinedRotation *= Quaternion.Euler(0, centerEye.transform.localEulerAngles.y, 0);
desiredMove = combinedRotation * desiredMove;
//cyber's code ends here
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
// ...
// leave the rest as is - cyberealityGrand ChampionThanks for sharing.
- SemicolonkidHonored GuestSo, I've followed everything cyberreality posted (and I used the C# variant of the code that paulLubos posted, as I'm using Unity 5), and I've got the weirdest behavior going on:
Everything works perfectly in every way, except when I use the mouse to turn my view, then the "move direction" shifts twice as many degrees. For instance, while holding down the forward button: I move North while looking North, when I look East I move South, and when I look South I move North.
Basically, as many degrees as I've turned, it's as if my desired movement has shifted twice as many.
However, when I use this with the Oculus everything works fine as long as I don't touch the mouse.
And if I don't implement cyberreality's code, then everything works as intended except then the Oculus doesn't turn your movement direction anymore (as expected).
Any idea what could possibly be going on?
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 21 days ago
- 2 years ago
- 9 months ago