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.