I must learn how to fly!

Hi everybody!

I’m fairly new in UE4 and I really need your help!

Basically, I’m working on my master dgree in numeric art and I deceided to use UE4 to present my environment in VR. I won’t tell you all the details here because I would need around 40 pages! XD

So, to make it simple, my subject is about 3D environment as a narative element in VR.

My problem here is that I really need to fly! But not exactly as you think…

I’m able to make the character levitate… That’s a good start. The problem is that, when he releases the levitate button, I want him to fall back to the ground and this is the main problem.

To give you a better idea of wat I want to do, here is an example.

Let say I make a game about Peter Pan or Superman or somethings in this category. I don’t like the idea of teleporting (considering I want to let the viewer exploring the environment). So I would give him the opportunity to fly. So, when you press the center bouton of the Vive Controller, instead of teleporting you, it will make you fly in the direction of the controller. When you release the bouton, I would like that the viewer start falling up to the moment he hits the ground. Then, if he was not too high, he survive, but if he was very high… well, he dies and respawn somewhere.

Up to now, I’ve got two problems :

  1. How to make the character fly (and not only levitate*).
  2. How to make him fall when he stops flying.

*When I say levitate, it is simple that I can make him go up, but not moving around)

Please, help me, I’m really struggling with this one! :-S

Cool project, really curious to see how it looks like!

Regarding giving your VR Pawn both walking and flying capabilities, the easiest way is to use a CharacterMovementComponent which does all the heavy lifting for you. This component provides both walking capabilities (with gravity) and flying capabilities (gravity suspended). If you are starting from the standard VR template, you can follow my tutorial here to switch the VR Pawn to use a CharacterMovementComponent and deactivate Teleportation altogether:

Once that is done, your character can walk on the ground using the thumbsticks.

Now to the flying part. You can switch to flying mode and back to walking mode using SetMovementMode:…tMovementMode/

To trigger the switch, you need to add an Input action event for it. Call it something like ToggleFlyWalk, link it to a key or controller facebutton and, in your Pawn blueprint call SetMovementMode from it. You can use a FlipFlop to toggle back and forth between flying and walking.

While flying, you also need to add a way to get yourself higher/lower respect to the ground. Just define an Axis event called MoveUp, with a key to move up (1.0) and a key to move down (-1.0). With that axis input event, use AddMovementInput with the actor Up Vector to move up and down along the Z axis (positive to go up, negative to go down).

Last but not least, when you toggle back from flying mode to walking mode, gravity will be re-applied and your VR Pawn will fall to the ground. At the time of the switch, you can use a** LineTraceByChannel** with a predefined distance (let’s say 300UU = 3 meters) to find out whether the ground is close enough to have your Pawn survive or not. If you get a Hit from the line trace your pawn will survive, otherwise it will die and you can respawn it somewhere else.

To make it die gracefully, you can use a StartCameraFade to fade to black (or white if you prefer), then respawn it and fade back.

Hope this helps!

Hi! Thanks for your answer! Strangely enought, my post have been sent without I knew! Let me explain! It was my verry first post here and every time I tried to post it, I was getting a 404 error. I thought it never worked and, now, I pass by the forum, try to post an other problem I’m working on and poof, I see this good old post have been sent! XD

For my project, I continued to work on it (even if I didn’t work on the flight part yet)!

Even if am very interested in your idea of using the thumbstick for locomotion, the center of my project is the immersion and the feeling of being able to walk helps a lot to get this feeling!

So, for info, here is what I did to get what I wanted!

  1. I created a sphere that I made invisible in game and I set it’s position in x and y to the VR camera.

  2. I activated the gravity on this ball and locked the rotations.

  3. I set the VR Origin position in Z to the ball’s Z position and voilà! My VR setup now uses gravity!

The other problem I had thought was that I wanted that the player would not be able to pass throught walls! So, I did some new modificaitons here :

  1. I made a new sphere wich has no gravity but has it’s phisycs enabled

  2. I set it’s position to the camera’s position.

  3. Now, every time, the sphere colides with an object, it’s position will be offseted to the camera’s position.

  4. I detect this offset and apply a negative transformation to the VR Origin and, once again, it works pretty well. Except for the teleportation that creates a lot of bug with all these things! Happily for me, my project will not use the teleportation!

I know I’m still really a beginner so if you find any better ideas from what I said here, feel free to tell me! :wink: