Download

Unreal VR Template - How to make the player fall off the edge?

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.

Any ideas? Thank you! :slight_smile:

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.

  1. 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.
  2. 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.



You will also have to define the isFalling variable (boolean, set initially to false) and the Falling Speed variable (float, I set mine to 10.0).

Last but not least you need a curve to drive the timeline. Here is how mine looks like. 3 seconds of pure panic. :wink:

For me that kind of forced up/down movement is one of worst things that can happen in VR…

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.

Thank you vr_marco, I will give this a shot. It sounds a little intimidating, but I think you were super thorough, so thank you! :slight_smile:

Any chance you could attach a template file I could just copy that blueprint code from?

I am so excited to try this!

@AtmaStudios Here you go. Enjoy!

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.

Well it is there anyway to support teleportation, so why not using it? Plus it’s fun to play with tags and timelines. :slight_smile:

Peace!

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.

Thank you. :slight_smile:

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.

https://www.unrealengine.com/marketp…ponents-plugin

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.

Thank you again.

@runeberg Can you please advise?

Hi!

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:

  1. Install the plugin from the Marketplace
  2. Enable it in your project (Settings > Plugins)
  3. Open the Pawn Blueprint and click the “Class Settings” button
  4. 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).

I hope that helps. Any questions, let me know!

Cheers,
Rune.

Thank you, I would love to try this but it looks like the Runeberg plugin is not 4.17 compatible?

HI Atma - It is compatible from 4.12 to 4.17 :slight_smile:

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:

https://www.unrealengine.com/marketp…ponents-plugin

Cheers,
Rune.

@runeberg

i get this error. I have tried turning autoactivate on or off.

remove the cameras, if u see in the left corner, when u got parented with the “runeberg” it creates the basics.

Sorry for my poor english :smiley:

@runeberg When I remove the non-Runeberg camera it all crashes instantly upon simulation.