Forum Discussion
DillonRobinson
12 years agoHonored Guest
Comfortable forced crouching?
Hello guys, I have a question here. As I near the end of my next project, I have an idea. In a couple areas throughout my diorama game, I have placed some chairs. I disabled their collision boxes, ...
DillonRobinson
12 years agoHonored Guest
Though, you should always be careful about any time you take over control of the camera (i.e scripted animations) as they can cause some people discomfort.
This is why I'm aiming for an ease-in and ease-out motion. I'm not quite sure yet if that would feel better, or to have the view snap to the lowered height automatically. But I guess that's something I'll have to test! It's difficult to pinpoint moments that cause discomfort when I have never gotten any sort of motion sickness from the Rift.
EDIT
Wow! So I was using if (forceCrouch = true) {} else {}
All I did was remove the "=true" and it started working! Very bizarre. I could have sworn they both meant the same thing.
I'm no longer in need of help, I trial-and-error'd my through it, it took 3 hours since I do not know C#, but it's working now :)
In case anyone else needs to do something similar:
Open OVRPlayerController.cs
Find where the var declarations are happening
(public class OVRPlayerController : OVRComponent
{...
)
There, I tacked on
////////////////////////////////////////////
public float heightStand;
public float heightCrouch;
public bool forceCrouch = false;
//////////////////////////////////////////
And at "new public virtual void Start()", added the lines:
forceCrouch = false;
heightStand = Controller.height;
heightCrouch = 0.5f;
I then made my cube and checked off "Is Trigger" in the Box Collider settings. I created a new tag CrouchZone, and added it to my collision box.
I added some lines between that mentioned Start() and the upcoming Update() with:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "CrouchZone") {
forceCrouch = true;
print ("zone hit!");
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "CrouchZone") {
forceCrouch = false;
print ("zone left!");
}
}
Under the existing "new public virtual void Update()", I added:
if (forceCrouch) {
Controller.height = heightCrouch;
print ("forceCrouch:" + forceCrouch);
} else {
Controller.height = heightStand;
print ("forceCrouch:" + forceCrouch);
}So what this does is, at runtime, sets a value based on the players height, which I can only guess is the same value grabbed from the Oculus profiler. When you hit the crouch zone, your height is halved to simulate taking a seat, and when you leave the zone, it's returned to what it was when the game began.
I wanted to do this so that you can both stand up and walk around, or take a seat and soak it in, like my last demo. It works pretty well for my purposes, but it's a bit buggy floor-collision-wise if you do it rapidly and try to run around while toggling it.
Note
I upped the Player Controller's "Skin Width" and doubled it from the default, as my player was falling through the floor on random crouches.
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
- 8 months ago
- 3 years ago