I want to add a collision capsule and attach to my character’s head bone. I was able to do this, but it seems additional capsules in the third person character BP don’t really work, it only takes the original capsule in consideration.
Am I doing something wrong or is it really impossible to add new collision capsules to the character?
Maybe I would have to add some function to the BP and reference to the new capsule so it also takes it in consideration?
Hello! Can you clarify what reason for is this capsule added?
If you are trying to add a second capsule so you collide with other objects when moving your character. That’s not possible with the current character BP. You will have to write your own character version with C++ and implement this feature or check if someone has made one on the marketplace. (You will also maybe have to check licenses if you use engine functions and expose them) What exactly are you trying to achieve?
I’m just starting to learn how to use UE4 and don’t really know how to code yet, so I’ve been learning to use the blueprints for now. I started out with the default “third person character” blueprint and started to play around to make it how I wanted it to be. I’m trying to do a cartoonish 3D platformer prototype (as a learning experience, not planning to actually have a full-fledged game).
So one thing I wanted to do was make the character align to the floor. Should be simple enough, just trace a line downwards and get the floor normal and rotate the character according to the floor angle.
I was able to do that (with help from forums and tutorials), and it worked fiine most of the time, but in some cases there was an issue: in the Third person character, the character’s origin is not on the floor level, but in the center of the capsule. This can’t be changed because the capsule can’t be moved. Because of that, if you stand on or near a sharp change in the floor angle, the character started to jitter violently. In other cases the character appeared to be floating.
So after asking for some help in this forum, someone suggested I should rotate the root bone of the skeleton (the root is placed in the floor level between the feet) instead of rotating the character actor.
This worked well and solved the previous issues. But it created a new one: it rotates the character mesh but doesn’t rotate the capsule, so if there’s a slope ending on a wall, the character will clip into the wall because the capsule is upright but the mesh is angled with the slope.
So I thought maybe I could create a second capsule parented to the root bone and also have collisions on that.
I know it’s far from an elegant and clean solution, but in my skill level I won’t be able to create a character from scratch.
What about gravity? or did you change the slope angle? If you rotate the character mesh instead of the capsule you wont get block collision on the character or you will get blank collision spots. You have to rotate the capsule. Use “show collision” command when you play the game to see the capsule in game and can you make an example of jitter.
“What about gravity?”
I don’t understand, what about it? Gravity isn’t affected I don’t want to change the gravity, just want the character to be aligned with the floor he is standing on, even if it isn’t realistic. I’m not trying to make the character walk on walls or anything like that, if that’s what you mean.
“If you rotate the character mesh instead of the capsule you wont get block collision on the character or you will get blank collision spots.”
yes, that’s why I wanted to create a second capsule so I could parent it to the skeleton and then it would rotate with the character and would be used to calculate the collisions. But I guess this isn’t possible.
“can you make an example of jitter”
I don’t know if “jitter” is the right word. I explain it better with images here: https://answers.unrealengine.com/questions/1028949/view.html
Thanks
In fact the idea is good however you should know, that default Movement component for characters is created for Capsule as Root component. So you can face additional problems if rebuild hierarchy. As for solution you can make it like that - let root capsule be for torso, while attaching others (foots, head, hands) to mesh. In this way, torso collision will be used both for movement and collision, while other collision components - only for collision.
And the question for Gravity is quite right too. Usually Movement component apply falling acceleration without any physics in fully kinematic mode.
I see what you want to do from the example. So what you have to do is rotate the capsule and then set the location of the capsule to vector = normal + offset capsule center. This will solve your feet clipping through. Then you still might get jitter cuz of setting rotation. With third person inside the BP when you move with WASD and mouse it sets a rotation. So if you set anther rotation they will jitter/jump to both rotations. What you need to do is get Capsule rotation and add your rotation and then set rotation. I will give you code examples later.
I tried to do the location offset. It didn’t work because when the capsule is offset, the collision changes and then a new location offset is applied, this happens continuously so the character starts to move erratically all over the place and it’s impossible to control him. I don’t know how to prevent that.
So as my code is now, the rotation is applied to the root bone and it’s working very well (no jitter and no floating at all, ever). The only issue now is the collision, that’s why I wanted to add more capsules. I added a new capsule but it doesn’t work for movement collision, but it does work for generating overlap events and stuff like that (I used one parented to character’s head bone to check if the character’s head is above water when he is swimming, and it works well).
If I could somehow cast hit events from this new capsule to the original capsule and make it affect the character movement it would solve my problem. I would reduce the original capsule to the size of the pelvis and add one or more new capsule parented to the root (or other bones).
“As for solution you can make it like that - let root capsule be for torso, while attaching others (foots, head, hands) to mesh. In this way, torso collision will be used both for movement and collision, while other collision components - only for collision.”
I like this Idea a lot. The only thing is I can’t make the new capsule actually affect movement. I can use it to generate overlap events but it doesn’t appear to trigger hit events, and it doesn’t prevent from going into walls like the original capsule does. I think I would have to somehow cast the hit event from the new capsule to the original capsule to make it ‘think’ that it’s hitting the wall even when it’s the new capsule that is hitting the wall. I don’t know if that’s possible.
“And the question for Gravity is quite right too. Usually Movement component apply falling acceleration without any physics in fully kinematic mode.”
I still don’t understand the issue with gravity. As my blueprint is now I’m not having any issue with gravity, it’s working well in that regard.
You could make on overlap then stop character movement and velocity, but that’s anther tick. I got it to work with just set rotation. Then changed camera to camera manger to stop the jitter.
I see, so if I understand correctly, using a sphere trace instead of a line trace it prevents the “jitter” problem, right? So that’s better than using the line trace like I did. But the character would still rotate around its origin (the middle of the character) instead of rotating around the floor level, right?
If you mean by jitter your character rotates up and down. Then yes. (You can also use line trace but make sure you offset it down far enough. Also line trace is not enough cuz you will collide with slope before you even line trace it. You can also Get Socket Location to get the root bone location.)
With this code I haven’t noticed the character legs going through the ground. (I was running it on tick. If I run it from event then the legs do go through.
I also had an issue with the camera and it was flicking/jittering fast when rotating. Fixed this by making camera manager and then making it follow the character.)
Hello again. Are working with BP or C++ solution is also interesting for you? I was hoping that it can be done with less routines but it seems that it require some tricky thing
Any ideas?
Unfortunately I don’t really know how to code in C++ yet, so I was hoping for a blueprints solution.
Well, unfortunately I am not very handy with BP and have more practice with C++…