I have a small VR game I am designing and I am curious how I can make the player fall off the edge of the level? For example, in the VR Template (it’s what I am using) if I teleport to the edge and walk/step off the edge, how can I make myself free fall down?
Would I apply gravity to the Pawn/Camera? I need the player to fall to their death.
Not trivial but doable! I am assuming your are working on the basis of the default VR template, so here is how you can do it.
You cannot make real “holes/open edges” because that would affect your Nav Mesh. In order for you to be able to teleport on the hole/open edge and fall through it, the hole/open edge has to be covered by the Nav Mesh.
You cannot use Trigger Volumes or anything similar to detect when you are on the hole/edges because your VR Pawn has no body and no physics, so that would not work.
The solution is to use hidden in game actors to cover the holes/open edges so that the Nav Mesh can still span over them, tag them with a special “Hole” tag and then use a downward Line Trace from your VR Camera position to check if you have teleported yourself onto them. If that is true, then you can start the falling sequence and a camera fade to black to communicate that dying sensation…
Here is how the level looks like (without and with the Nav Mesh). The red actors represent the falling edges and are tagged with “Hole”. They are Hidden in Game.
Once the setup is ready, you can go to the Event Tick of your VR Pawn, add a pin to its Sequence node (the one from the default VR Template has already a couple of branches to manage the teleport rotation for each controller) and use this code.
Actually I thought the same before trying it out, but it is not too bad if you keep it slow and fade quickly to black. Of course it may be scary to some, but so are many VR games anyway.
He specifically stated “walking off of the ledge” after teleporting to the edge of it. The whole navigation setup isn’t required for that…
It can be done with just floor traces on tick and applied gravity when over an opening and would work in a general sense as well without additional map actors and volumes.
mordentral, could you please give me an example of this simpler method? You understood correctly, I was hoping to allow people to teleport to the edge of a cliff or bridge and if the player walks out of the nav mesh bounds, or off of the cliff, they will fall down endlessly to their death.
You mention floor traces on a tick, but I am not sure what you mean? Thank you in advance.
I am using the built in Unreal VR Template with Motion Controllers if that helps.
You can keep just that trace section from his blueprint screenshots (and I assume the project link), it checks downwards for the floor and if there isn’t one in range it sets IsFalling to true. Then when IsFalling is true you apply a downwards velocity each tick that ramps up by GetGravityZ
So as long as IsFalling is true then add the result of the GetGravityZ node to a variable (fallingSpeed) and apply that as AddWorldOffset(fallingSpeed * deltatime) (so its over frames).
When IsFalling is false, reset fallingSpeed back to zero.
You’d also want to clamp the falling speed to a maximum value (a terminal velocity).
This is the simplest form of a floor trace / gravity setup, there is a lot to add to it (like sweeping the capsule and not a line), but it would get you going and most of it is already in his example above.
merdentral, I have no idea what you are suggesting. I do not have that kind of grasp or knowledge of the Unreal engine yet. I am at the stage of understanding triggers and basic responses, turning on and off physics, destruction meshes, lights, etc. If you could make a template as well, maybe that could help myself or others. We could possibly choose between your idea and vr_marco’s depending on whoever might be easier for the person seeking the solution. I imagine I am not the only one with this question.
I already provide a solution for this kind of thing but it is a ton more advanced and likely a little out of your comfort zone currently. If you want to learn blueprints then this is a good starting project as it is fairly simple and a good initiation to basic blueprint nodes that are commonly used.
Also as I said, most of it is already in his template he was kind enough to provide for you.
Edit Actually I checked Runebergs VR plugin and it has a flat value gravity option on it, you could use that as well since it is on the marketplace it is easy to install and use. It is kind of an in between from teleport only pawns to full characters, likely suited to your use.
Thank you. Okay, another question. Is the Runeburg’s plugin compatible with the Unreal VR Template? I have already built a HUGE part of my game around the Unreal VR Template and I could not imagine rebuilding it.
The plugin can be integrated to existing VR projects.
As you need the Gravity feature, this is part of the VR Pawn and as far as I recall, the VR Template also uses the Pawn class, so all you should need to do is to change the Parent Class of your Pawn. To change the class:
Install the plugin from the Marketplace
Enable it in your project (Settings > Plugins)
Open the Pawn Blueprint and click the “Class Settings” button
Under Class Options “Parent Class” change this to RunebergVR_Pawn.
Only wrinkle I think is you’ll get extra Motion Controllers there, the VR Template uses Child Actors for the controllers – try unticking “Auto Activate” on both Inherited Motion Controllers so it doesn’t take any extra resource and you can safely ignore (untested, if you encounter problems with the controllers, reactivate).
Are you having any difficulties making it run in your current project? If so, let me know the exact message and prompts you are getting and I’ll see if I can help.
The easiest is to download it from the Marketplace via the Epic launcher: