How does the character automaticly rotates towards gravity direction in UE templates?

As I know, it is the default situation for character in UE. I am working on a project that really needs that feature, yet I cannot managed to implement it, it’s not working when I set things up for my character. I opened a few previous questions for that, you can check them out if you wanna help me and get more details about my problem.

Simply, the gravity direction often changes, giving the character ability to move, or walk if you say in every surface. But also the character must rotate by gravity’s direction, all the time.

Here is my current situation in real game project:

And here is what I managed to get (which was really simple) in an Unreal Template:

@ClockworkOcean @Mind-Brain @gardian206

By the way, yes in template, line traces are not firing at the right direction when character’s rotation changes, however I didn’t had that problem when I move to the real game project.

for example I have a 3rd person template where I shoot a line out of the capsule, but it is the assignment I am concerned about

the DrawDebugLine() was put in to sanity check the vector.

I put in a timeline with X:[0,3] (3 seconds) and Y:[0,1]. I do end up lerp on the vector because getting a rotator, or quaternion isn’t as effective in Blueprints.

you can play around with the timeline, and remove the debug line, and the branch, you could even keep them for say an obstacle (entity, triggerBox, or secondary affect) that instantly forces gravity in a given direction; just be careful as too rapid of orientation switching can easily make players motion sick, or at the very least disoriented (unless that is your intent :frowning: )

I am seeing some misunderstanding of the FHitResult

  • ImpactNormal: the vector that is opposite the force being applied to the object (think of this as the line pointing back along the instantaneous hit)
  • Normal: the vector that is normal to the point of impact relative to the surface (think of this as the line pointing exactly away from the surface at the point of impact)

so given a cube, and a collision happening at 45 degrees to the surface, the ImpactNormal will be pointing back along that 45 degrees, and the Normal will be perpendicular to the surface.

to use that Normal vector as Gravity you need to take the negative of the vector (there is a Negate) because given the implementation you would want that “Normal” to be your character’s “UpVector”

____

when you have a transition lerp for the rotation, keep in mind that you may need to either disable the reassignment of your TargetGravity, or accept that your player may be able to switch the TargetGravity mid rotation, and end up in precarious positions (again dependent on your intent)

you could even introduce puzzles that disable the ability temporarily (while in TriggerBox disable gravity shift)

also be aware for the good or bad that this changing of the gravity frame only applies to the Character itself, and SetGravity only applies to Entities with a UCharacterMovementComponent, so to use it with say Pawns you will need to modify their MovementComponent to accomodate for gravity frames (which is not exposed to Blueprints, so you will need to go through C++)

My intent is, the character will have 2 main line trace systems, techniclally very similar to each other. One firing below the character and rotating it all the time when the surfaces rotation/direction change, other one firing above, making the character a skill of changing direction rapidly with a jumping like motion. Both of theirs firing location and rotation must be relative of characters situation. Character will have no external gravity or physics system than that. Also the camera will follow the character as it’s rotation changes well, but it will follow smoothly.

For now, if we were to fix the first problem in the line, can you help me, simply get the rotation by gravity feature that default UE character has?

And as my understanding of my impact normal, practically it must look 90 degrees straight if you shoot from a 45 degree angle, like this: Am I correct?

Not sure if this will keep working as I set up more stuff , but I just did the first thing that comes to mind :rofl:


Yes, not working :frowning:

I am not sure what exactly is incorrect about the last video you showed.
Paper2D uses a specialized physics system (Box2D) that tries to force character orientations.

the biggest issue I see in your initial video here is that the camera is skewed, which I feel is a result of taking the rotator, and multiplying it by a scalar of 2?? (if you take a rotator of <Y:10, P:15, R:0> you will get <Y:20, P:30, R:0> which is very different orientation)

as for in 3D setting the Character’s Gravity Orientation (as of UE5.4) mostly trial

you can see some of the problems that the camera gets into, and to fix that stuff you need to do work on either the CameraController, CharacterController, or the CharacterMovementComponent which any of those would need at least a little C++ (each of these are available with some searching online for something like “Unreal Engine Gravity Camera”), but will in most cases require changing the the input processing for look and movement.

1 Like