Forum Discussion
AdamL288
13 years agoHonored Guest
Problems with mouselook script
Hi all,
I'm still fairly new to programming in Unity but I've made good progress so far. As I'm not a massive fan of the default Player controller I have decided to try and make my own as a prefab using OVRCameraController. I have based this off the following setup that came with a demo I bought on the Unity asset store:
- First Person Controller (capsule object) - uses mouselook.cs from the standard assets folder in the X direction
--- "head" object with view-bobbing animation
------ Camera object - uses mouse look.cs in the Y direction, as well as image effects
This setup works with a single camera, and reading through the comments of mouselook.cs this appears to be correct. However, after replacing the single camera with the OVRCameraController, mouselook no longer works at all (in either X or Y). I can't work out why this would be the case, as the script does not appear to have changed.
It's rather difficult to explain so if this isn't a common/silly question then I'm happy to upload a copy of my project to clarify.
Thanks,
Adam
I'm still fairly new to programming in Unity but I've made good progress so far. As I'm not a massive fan of the default Player controller I have decided to try and make my own as a prefab using OVRCameraController. I have based this off the following setup that came with a demo I bought on the Unity asset store:
- First Person Controller (capsule object) - uses mouselook.cs from the standard assets folder in the X direction
--- "head" object with view-bobbing animation
------ Camera object - uses mouse look.cs in the Y direction, as well as image effects
This setup works with a single camera, and reading through the comments of mouselook.cs this appears to be correct. However, after replacing the single camera with the OVRCameraController, mouselook no longer works at all (in either X or Y). I can't work out why this would be the case, as the script does not appear to have changed.
It's rather difficult to explain so if this isn't a common/silly question then I'm happy to upload a copy of my project to clarify.
Thanks,
Adam
7 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionRemove the mouse-look script from the OVRCameraController.
Then add the "First-Person Controller" to the "Follow Orientation" of "OVRCameraController".
Make the following edits to FPSInputController.js:
Add this to the top:public var ovrCamera : GameObject;
Change this line:motor.inputMoveDirection = transform.rotation * directionVector;
To this:motor.inputMoveDirection = ovrCamera.transform.rotation * directionVector;
Go into the inspector and drag "CameraRight" onto the First Person Controller value for "Ovr Camera".
Now it should work similar to the sample integration. - AdamL288Honored GuestThank you so much! Took me a while to get my head around that solution but it works perfectly :) cheers.
One more question - I've noticed there is code for handling jumping but I can't seem to find the key to do this. Either it's not set up or I don't know which key to use, any ideas?
Thanks again,
Adam - cyberealityGrand ChampionIf you're using the default First Person Controller, I believe the Space Bar is used for jump.
Works for me. - AdamL288Honored GuestThanks again for the reply, turns out I'm an idiot and had the enabled flag un-checked in the Character Motor script :P
- keptblueHonored GuestHey guys,
It seems the mouse look script only works with rotation around the Y axis. I'm trying to make a floating camera that can also adjust the pivot of the horizon.
I've replaced the mouse look script with a simple free look script:
var rotationX = 0.0;
var rotationY = 0.0;
function LateUpdate ()
{
rotationX += Input.GetAxis("Horizontal");
rotationY += Input.GetAxis("Vertical");
transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
}
Unfortunately when the Oculus moves, the angle of rotation is skewed. Can anyone provide some ideas on how to correctly apply the rotation? Perhaps this is more complicated than I thought, and I might need to implement 6DOF.
Much appreciated for any advice.
//andyd - keptblueHonored GuestYo dudes,
I just wanted to update with a solution for this issue using 6DOF a la this thread: http://forum.unity3d.com/threads/73406-6DOF-banking-and-pesky-gimbal-lock. Here is the script-- note that "cam" is replaced with the right camera of OVRCameraController, which is set to follow orientation of the gameobject which attaches this script.
private var pitchYawSpeed = 120;
private var rotationSpeed = 60;
private var moveSpeed = .1;
public var cam: GameObject;
function Update ()
{
// Pitch/Yaw ship
transform.Rotate(-cam.transform.right * (-Input.GetAxis("Vertical 2") * pitchYawSpeed) * Time.deltaTime, Space.World);
transform.Rotate(cam.transform.up * (Input.GetAxis("Horizontal 2") * pitchYawSpeed) * Time.deltaTime, Space.World);
// Rotate ship
transform.Rotate(cam.transform.forward, -Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime, Space.World);
// Forward
transform.position -= cam.transform.forward*moveSpeed*Input.GetAxis("Vertical");
}
//andy@extlabs.com - johnmcgheeHonored Guest
"keptblue" wrote:
Yo dudes,
I just wanted to update with a solution for this issue using 6DOF a la this thread: http://forum.unity3d.com/threads/73406-6DOF-banking-and-pesky-gimbal-lock. Here is the script-- note that "cam" is replaced with the right camera of OVRCameraController, which is set to follow orientation of the gameobject which attaches this script.
private var pitchYawSpeed = 120;
private var rotationSpeed = 60;
private var moveSpeed = .1;
public var cam: GameObject;
function Update ()
{
// Pitch/Yaw ship
transform.Rotate(-cam.transform.right * (-Input.GetAxis("Vertical 2") * pitchYawSpeed) * Time.deltaTime, Space.World);
transform.Rotate(cam.transform.up * (Input.GetAxis("Horizontal 2") * pitchYawSpeed) * Time.deltaTime, Space.World);
// Rotate ship
transform.Rotate(cam.transform.forward, -Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime, Space.World);
// Forward
transform.position -= cam.transform.forward*moveSpeed*Input.GetAxis("Vertical");
}
//andy@extlabs.com
Hey there, I realise this is probably a dead thread, but I though I may as well ask; I'm trying to use your script here to give my OVR player free-movement, though I'm not sure what object I should be applying this to. Is it directly to the OVR player controller? If so, do i need to disable any of the other movement scripts associated with it? My player is currently locked in place (translation-wise. I can still look around with the Oculus head-tracking). I've been trying to work out a free-movement solution for a while, but my limited coding skills are holding me back
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
- 5 months ago
- 10 months ago
- 9 months ago
- 8 months ago