VR Doors - Unreal C++
I think my door mechanics are some of the best doors made for VR.
They involve these things (ordered by hardest - easiest to implement):
A UseDoor() function for pushing/pulling the door while grabbing.
A Swing() function for when the player lets go of the door.
Two quaternions representing the max and min rotations of the door.
A door hinge location / rotation (USceneComponent).
A knob collision sphere for the player to grab.
A door mesh.
Two bools for setting the door state (bUseDoor, bSwing).
Here is what the tick function looks like for our Door class:
When the player grabs the door, we set bUseDoor to true so that UseDoor() gets called every frame until the player lets go.
Here is UseDoor():
MinRotation is an FQuat that represents the rotation of the door when it is closed.
MaxRotation is an FQuat that represents the rotation of the door when it is all the way open.
MaxAngleRadians is the Max angle that the door can be from the min or max rotation.
Once the player lets go of the door, we set bUseDoor to false and bSwing to true.
Here is our Swing() function: