Gravity affected flight movement using character movement component

I’ve got a player I’m working on that needs the ability to fly. I know that the player movement component has a flight mode, but when I go into that mode it disables gravity. I need gravity for the flight since I want it to be more like flying like a bird or in Sky (Children of the Light).

I’m currently trying a custom movement mode but it has a few issues. The code is as follows:

The issues are that if I bump into a cliff or the edge of an object, my player just kind of gets stuck there. I was thinking of replacing this with a square collision check, but then I’d also need to get the normal of the ground to check if it’s a wall or the ground on a lean, etc…

So I have two questions:

  1. If there is a way to fix up the above so that I can safely detect landing, how would I do it? The other half of the problem I have about this is that in the modes “Flight” and “Dive”, my whole player will be rotated around to face the direction they’re moving, so is there also a way for me to account for this when I do them?
  2. If the above is either too complex or too difficult, or there is a much easier way to do this, what should I do?

I’m not really in a rush for this, I do have a few months before I actually need this, but I’d like to get it sorted as soon as possible. Any help is appreciated!

Edit: I did manage to get landing safely working using this


Could probably get the actor hit & switch based on type to enable swim if needed or whatever?

That aside, I’d still like to know if I’m just overcomplicating this and there’s a better way to do it…

What about applying your own Gravity Force with flying mode enabled?

In tick you could apply additional force to your character like this:
FlightGravityForce (your customizable gravity force float parameter) * Vector Down * Delta Time

I think you are overengineering it.

Collision detection and correction is already handled for you. Try using AddImpulse and AddForce instead.

  • As @lordlolek said either add a continuous gravity force in your flying behavior…
  • Or use normal movement where you add impulse on a key press to get a kind of a “Flappy Bird behavior”

Check how Jump is implemented. The only thing preventing it from double/triple/quadruple jump is a check weather you are on the ground. If you remove that check, each time you jump it will actually propel you up. And if you reduce the gravity and increase air control you will get more of a gliding behavior.

I’ve tried AddForce for both actor and for the character component, it either just doesn’t apply on a low number or if I set it to something like 98000 only when I’m very close to the ground. My teacher said to try to avoid using add actor offset since that could make things buggy in the long run so I’m not sure if that’s right?

As for what @dZh0 said, I’ve been trying add impulse too and it kind of just shoves the player into the ground until the point I can’t move, at which point it ends up feeling like just using custom and making custom code for each flight mode feels more reliable.

The jump part does sound helpful though. I would be able to control in the air I’m assuming, but would that also work for the flight and dive? Not sure if it would.

You’re right, “Add force” is a bit hard to handle at the begining, but it should work with some fiddling.
Jump is a nice idea, I don’t recall it being customizable without going into c++ tough?
I think Launch Character node works very similarly to the Jump, but you can input any vector you want.
and btw I agree with your teacher about Add Offset for such cases. But Add force is entirely different, it uses physics to push objects and is intended way of simulating forces like gravity.

then why dont use the falling mode?

Trying to avoid C++ since I also want to be able to use this for a uni project next year, and we discovered last year that the artists don’t really know how to use UE5 with C++ so if I can avoid it it would be nice.
Do you know if there’s a limit to add force? Like something that will make it work? I’ve done some searching on forums but the only thing I’ve ever seen people say is that it either needs an extremely high amount or just doesn’t work with flight. If I can just swap to flight and use that instead, it would be highly appreciated since I feel like it would work much better for all three flight modes.

Would that work for all three flight modes? If it would I’ll definitely look into it. The three all have different movement styles, with glide being a hover, flight being actually flying (the easiest way I could compare this would be like the plane controls in those realistic war-inspired games), while diving would be slowing picking up speed while flying almost directly downwards.

If you need all three to work with gravity, then yes, within the character movement component you have a section for the falling variables. There you can see which parameters you can change in the BP. Just remember to return them to the default value when you finish your custom movement. Also, make sure you have an Input mapping context for each movement.

Did some quick tests with falling, I think that would work. But is there a way to allow the player to apply input to push them down/up in blueprint instead of C++? I do have Add Movement Input which is auto set up to allow movement in all directions (including Z) but it doesn’t seem to do anything beyond XY for falling?

movement update component, That overrides everything, but add Movement input should be work, try change air control to 1 or put some boost

THAT WORKED! Definitely works better than the custom code! :smiley:
Thank you so much