Tutorial: Custom Gravity in UE 5.4

Quickly added this to my First person project, it works great, except for one issue. It doesnt seem to rotate the capsule component, just the mesh. I cant get close to what would now be the wall on the -z side as my capsule is in the way.

As you can kinda see in the image, its offset to the -z direction. Is this fixable? or maybe just because I’m using the first person template?

The other issue is I’m doing a line trace(complex) in the gravity direction to get a new direction when walking over curved surfaces but I get a lot of jitteriness, even when I have the gravity with a VInterpTo node. The jittery might be when I’m walking past an edge on the mesh, but I figured the vinterp would smooth it out better…

1 Like

Hello
Could you please help with a problem in build.
I can’t build the code you gave in Visual Studio. What am I doing wrong?
I did exactly as in tutorial. Deleted all data that was in the file and pasted the code from you example. Did not write it myself, simply copy pasted.

1 Like

is this replicated?

Hello @Ari_Epic how would I get objects like the cubes from the third player template to obey the new rules of gravity?

Error:And while following Unreal Univeristy’s tutorial for a main menu from 2 years ago, running the editor from from his main menu and pressing start the game level loads up with the gravity not functioning, but if I skip the main menu and run the editor directly into the game level, new gravity works. Could anyone help?
Edit: Solved The game needed more time to load inbetween level changes, character would spawn faster than the level and events failed to fire.

@StellarDrop

Could you please share a picture or pictures of how you’ve achieved the camera stability using your method of detachment

Ive been painfully trying everything to follow what you’ve suggested and anything i can think of for months to get my camera stable, all in vain

I Would greatly appreciate it
Thank you

Thanks for this Custom Gravity code!
Custom gravity is working with the Walking movement mode but not Flying.
How do I ensure custom gravity works with all movement modes?

Update: I’m going to create a UPlanetaryMovementComponent class that inherits from UCharacterMovementComponent to allow for all Movement Modes with Custom Gravity.

@Interitus384 I got the capsule to rotate properly by using a hit event and tagged “wall” and if true set new gravity to normal of the wall (negated) also rotated the capsule using the same hit normal negated.
The risk is if the hit event is on an uneven surface the capsule will also be and remain so untill corrected. You could do this with a time event and line trace.

I’m curious, did get the camera/aiming pitch and yaw working correctly while on walls or ceilings?

Hello @Ari_Epic! Thank you so much for your tutorial, It helped a bunch for my school project, however, for this same project i need to create an AI that can have all the same behaviour of a normal AI but while moving on the planet sphere. Would i have to create another C++ class for an AI controller, or is there an easier way to go about this?

I have also noticed that nav mesh does not work at all on spheres, do you think i would be able to circumvent this by simulating movement inputs instead? I’m quite new to Unreal game development so I also don’t know how compatible this would be with behaviour trees.

I would appreciate any tips or help at all, I have nothing to lose and everything to try xD
Have a nice day!

Hi @ISX2000, creating an AI that can go around a planet is probably going to go a bit against the grain of some of UE’s systems. I don’t think navmesh can go around a circular surface for example. I haven’t tried it myself so I’m not sure what needs to be done to get AI working with this, sorry to not be able to be of more help :man_shrugging:

Hi @Ari_Epic ! i tried a few different things and in the end what works most reliably is coding the behaviours into a Character class myself so at every tick the gravity direction can be updated. In the case of a following AI, I create a normalized movement vector with the correct direction and feed it with an Add Movement Input node (see below)

thanks for the response though! I appreciate it :slight_smile:

1 Like

Hiya,

This is great! Got the thirdperson working in my projects, real nice.
Any tips/hints on how I could get this to work with a firstperson view/character?

Best,
Marcel

got exactly same error …

Thank you, your solution save my game

Thank you, thank you. I was worried this might be a complicated fix, but delighted it was so simple.

Hello I have followed your tutorial but i am unable to make the Get Gravity Direction Vector Variable appear in blueprint, what creates the Get Gravity Direction Vector for you to use in the first endcap solution with flipping gravity on contact with a trigger? Thanks,

I have created a new blueprint but i do not know what blueprint location the script should be in whether level, character movement, or a new custom blueprint as I have made, none of the available options, get gravity direction, set gravity direction, and the get gravity direction variable seem like the one you used in your solution and none of them work


edit i was able to solve this issue by right clicking the gravity Dir struct pin on set gravity direction and designating it to be promoted to a variable but I’m still not sure in what blueprint to place the script though for it to work interacting with player character?.

How do I reference which volume I want to have the effect added to it?

This is what my script looks like now but I still think I’ve done something different

you can edit your camera/boom distance and toggling the ability not to see your character is also an option in the same settings i think

@greatmazingerz
@dimabolgov
you have to install more visual studio components showing in the top right where the errors are and keep doing that until it has no more to install then compile

1 Like

Not to necro this post but how did everyone get maxwalkableslope to behave? It seems as though my character can get stuck falling.

i think a lot of people have trouble cementing the concept or we’d probably have better games lol

■■■ get much worst after that
so many errors …