collapse

Welcome to VRTITTIES

A place for VR Porn Games, Oculus Rift Porn Games, Vive Porn Games, VR Porn Game Downloads & VR Sex Games.

Please feel free to discuss anything about Oculus Rift Porn Games, Vive Porn Games and VR Porn Games.

The answer to the anti spam question is facebook. If you have any issues registering then flick me an email or post as a guest. If you make an account you do not have to answer any anti spam questions after 10 posts.

You will need to sign up to the forum and make a number of posts before you can post links to other websites.

If you are ever looking at buying some VR Porn please use my affiliate links on the right sidebar.

Thanks,

VRTITTIES, New Zealand

Chelsearift@gmail.com


Author Topic: Tutorial - Setting up controls to raise and lower the camera in Unity3D  (Read 12457 times)

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Hi everybody,

Here's a fast note about how to enable raising and lowering the camera using the gamepad shoulder buttons in Unity3D. There may well be better ways to do this, but here's what I've done in my own projects. (If you've found other/better ways to manage this, please share here!)

By default, your gamepad shoulder buttons are mapped to a rotation snap. Maybe useful for some things, but for this sort of thing, raising and lowering the camera is pretty much a must.

This tutorial assumes the OVR 0.4.4 Oculus Unity integration.

Here's how:
First, you want to unlock your camera from the player's profile height. Do this by selecting the OVRPlayerController in your scene and unchecking Use Profile Height.

Now, we need to make a minor script change to our player controller script to allow us to feed new height information to it.
Double-click the OVRPlayerController script to open it in MonoDevelop.

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
We're going to modify the UpdateMovement() method.

On or around line 244, let's remove the LeftShoulderButton binding from curHatLeft.
Replace this line:
Code: [Select]
bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);With this:
Code: [Select]
bool curHatLeft = false;(You could always map some other input to curHatLeft if you still want it. I didn't need it, so I'm just leaving it off.)
Do the same to curHatRight, on line 253:
Code: [Select]
bool curHatRight = false;
Now, right at the end of the method, right before the closing brace around line 298, insert the following:
Code: [Select]
Vector3 adj = new Vector3(0.0f, 0.01f, 0.0f);

if (Input.GetKeyDown(KeyCode.Alpha5) || OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder))
CameraController.transform.localPosition -= adj;
if (Input.GetKeyDown(KeyCode.Alpha6) || OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder))
CameraController.transform.localPosition += adj;
This will simply subtract 0.01 from the camera controller's Y position for each tick that the LeftShoulder is down, or add to it whenever RightShoulder is down. If you wanted your camera to raise and lower at a different rate, you can change the Y value in the adj vector accordingly.

(Please note that the Oculus 0.4.3 integration contained a bug in OVRGamepadController.cs that prevented it from properly feeding shoulder button input to the player controller. This is fixed in 0.4.4.)

That's it! Now you should be able to raise and lower your camera using the gamepad shoulder buttons.

Testease

  • VR Porn Fiend
  • ***
  • Posts: 75
  • Procrastination: working tomorrow 4 a better today
Thanks again! I haven't tried using my 360 controller yet but it works great for alpha 5 and 6. I'm curious how to increase the height change increment, .01 requires a lot of button pressing. I've also played demos that let you hold the button and the height continued to change, currently a key press is required for each increment.

Edit:

I figured out the first part of my question, I just changed 0.01f in this line "Vector3 adj = new Vector3(0.0f, 0.01f, 0.0f);".
« Last Edit: December 07, 2014, 09:56:08 PM by Testease »
If you build a man a fire you keep him warm for a day. If you set a man on fire you keep him warm for the rest of his life.

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Yes - you've got the idea - changing the vector increment to some greater value like
Code: [Select]
Vector3 adj = new Vector3(0.0f, 0.1f, 0.0f);would move the camera further per tick (in this case, 10 times further).
The gamepad treats these as continuous inputs. To be honest, I haven't really messed with the keyboard controls much at all since I use the gamepad pretty much exclusively. Probably the most effective way to treat the keyboard and the shoulder buttons equivalently would be to toggle a flag on when the key or button is pressed, and flip it off when it's released, and then in the update, check for the status of the flag and add in the adjustment vector if it's true. I'll do some experimenting with this and submit updated code if it works out. It wouldn't be a bad idea to multiply the increment against the frame's delta time to ensure that the camera moves at the same rate regardless of framerate. I'll see what improvements I can work out and drop some updated code here once it's behaving.

PornulusRift

  • VR Porn Fiend
  • ***
  • Posts: 91
    • PornulusRift
If you use GetKey() instead of GetKeyDown(), holding the button down will cause it to be called each Update().  GetKeyDown() will only return true the first Update() that the key is pressed.

Testease

  • VR Porn Fiend
  • ***
  • Posts: 75
  • Procrastination: working tomorrow 4 a better today
Thanks PornulusRift, it seems so obvious now.
If you build a man a fire you keep him warm for a day. If you set a man on fire you keep him warm for the rest of his life.

 

* Download VRtitties

* VRtitties Affiliate Links

* Forum Staff

Will admin Will
Administrator