Need help making character align to floor

I’m having trouble trying to make my character align to the angle of the ground he is standing on.

My method is to use a LineTraceByChannel pointing down to get the ground angle where the character is standing and adjust the character rotation accordingly. It’s working very well except in the specific condition of being near a steep angle change in the ground.

What happens is the line that is traced points to the character “down vector”, so when the character rotates the line then hits the ground where the angle is different, so the character rotates back and it gets the previous angle again, so it rotates again, and creates a loop that makes the character rotate back and forth violently.

I tried then making the line always point straight down, regardless of the rotation of the character. This was much better, because now the character doesn’t swing back and forth, but it creates a different problem: depending on the angle change in the ground, the character might look like he is floating.

And there’s a second (smaller) issue that happens in both cases: if the character lands on a slope and doesn’t move, the rotation will make it’s feet sink into the ground. If the character moves this is corrected because the capsule collision corrects it, but if you stay still as soon as you land, the feet will sink in. But this is a smaller issue that I’m willing to live with.

All this happens because the pawn in the third person character has the pivot point set in the center and not the floor. If it was in the floor the character would rotate around the floor point and all these issues wouldn’t happen. But it’s impossible to move the capsule, so the pivot point has to always be in the center of the character. Knowing this, is there a work around? Would really appreciate some help.

Below I have illustrated the issue so it’s made clearer:

With line pointing to character’s “down vector”:

With line always pointing straight down (much better, but still has issues):

If your character skeleton root is at the bottom of the mesh (between the feets), then you can rotate that root instead with the anim blueprint, so you would have a pivot point that is to the ground and not in the center of your character

Thanks! I’ll give it a try. I suspect that this would make the mesh misalign with the collision capsule, causing different issues regarding collision. But it might be a good trade-off even so.

I just realized I have no idea how to control the root via blueprint. The skeleton has a root bone and it’s placed between the feet, but I don’t knot how to set the rotation via blueprint.

For that you can use the “Transform (Modify) Bone” node in the AnimGraph. In the details of this node you select the root, you can untick “Translation” and “Scale” because you will only use the “Rotation”, and in the Rotation submenu I would try with Scale Mode : Add to Existing, Rotation Space : Bone Space.
Then you can feed a variable to this node, that would be the rotation that you add in runtime to your mesh (which I would modify in the Event Update Animation of the anim Blueprint.

But yes like you said, the mesh will rotate but not the capsule, so there might be some weird collisions happening depending on what you need

Thank you very much! It works!
Now for the collision issue of the capsule not rotating with the character, if I could add a different collision capsule attached to the character’s head bone it would prevent him from clipping into walls because of this. I was able to add the collision capsule and attach to the head, but the collision of this new capsule doesn’t seem to work. If you know how to add a second collision capsule to the third person character blueprint, I would really appreciate if you pointed me in the right direction.
Again, thank you for the help!

@Xandeta… welcome! I’ve struggled with similar issues for quite a while (a week or two).

In general, the UE4 Character (not Pawn) class is EXCELLENT at what it does, but for efficiency and networking reasons isn’t very flexible in some areas. To expand it’s behavior range does often take quite a lot of skill to modify the Character C++ to expand it’s behavior range.

Fortunately, there are some people who have done this work already: here on the forum, also as paid and free plugins. For my project, the 100% free Ninja Character plugin works INCREDIBLY well, but it depends on exactly what behavior U are looking for. Good luck and I hope this is useful :slight_smile:

1 Like

That’s really cool. I searched for it on Youtube and it looks awesome.

I’m still learning how to use Unreal Engine, and I’m doing a small personal project as a self-teaching experience (“self-teaching” may not be the right term, I’m learning from random online tutorials and people on this and other online forums). So far I’ve edited quite a bit of the third person character blueprint to make it more like what I wanted, so changing the character BP now would mean losing all the work I’ve already done. I’ll keep in mind for future projects, though. Starting from this ninja character would make many things a lot easier.
If you want to check out my progress (I would really appreciate some feedback) here’s a video I took of my work in progress (I modeled and animated the character, landscape and assets as well):

1 Like

I’m loving the smooth animation transitions, and the stylized character/world, and the camera angles. Looks sensational!

As U know, with the difference between ‘gameplay’ and ‘cinematic’ cameras… some of the camera angles look awesome but may not be quite right for gameplay (because the player can’t see where they are going or aiming). Here’s a great talk by the ‘Journey’ camera programmer 50 Game Camera Mistakes - YouTube

1 Like

Thanks, I’m watching the video and there’s really helpful information.

Since the time of this post I’ve put my game prototype up for people to download it (for free since it’s a prototype):
https://alemarcati.itch.io/jetman-game-prototype

Would love to get some feedback.