"Where" exactly is gravity applied to a Character?

I want to change how gravity affects my character, specifically so that it can walk on a sphere, while still keeping most of the funcionality of the Character class. I know that I need to modify the engine to do this, and I haven’t done any c++ coding in unreal before, so I’m still trying to get the hang of things. My idea was to find the implementation of gravity, figure out how it works, and then change it.

What I tried doing was to follow the Movement Component’s getGravityZ() method, hoping that it would lead me to where gravity is actually implemented, but it only led me to this line of code:

GlobalCreatePhysicsDelegate.Broadcast(this);

Which I’m guessing means that the physics in Unreal acts on objects, so I would need to change code there to accomplish what I wanted to. Still, I saw a video someone made, where he did exactly what I was looking for, and he supposedly only extended the Character Movement component. Here’s a link to the video. Of course I wouldn’t need anything this complicated, only the ability to walk on a sphere. (I want to make a game set on a small planet, kind of like the Little Prince)

Since I’m a complete newbie I would also appriciate just general help on how I might go about learning about how some parts of the engine work. I tried going through the documentation, but I didn’t have much success.

Gravity is handled in “SimulateMovement” method

Simply disable the gravity on the pawn and add a your custom code on top of it ?

inside tick method of your character movement, you can can do :
Velocity = NewFallVelocity(Velocity, gravityDir*GetGravityZ(), DeltaSeconds);

where ‘gravityDir’ is a normalized vector to your gravity point from your player :slight_smile:

you would have to rotate your player too i suppose :slight_smile:

Thank you, I will try that.

Wow that worked beautifully, thank you!

Can you explain with a little more detail how to make this work? I am very new to c++ (in fact, I started it just to make this single function) so it is hard for me. How do I disable the gravity and where are the stated “SimulateMovement” method and tick method located?

It works but only if the movement mode is set to flying, this also disables friction completely.