Hello forum.
So after a few days of struggling I’ve finally managed to modify the TPS sample blueprint enough to fit it for an realistic first person character.
By realistic I mean a character in which the player would feel like in a normal human body.
I’m putting this here for two reasons: If you’re trying to get the same effect, feel free to use some elements here for reference. If I get requests, I can make a video tutorial on setting the thing up. Second reason is for myself. Since I’m not extremely experienced in ue4 (working in it for 2 months) I know there might be some errors here. If you have a better idea for some blueprints, let me know.
Also note: This is NOT 1000% done. Some tiny details have been left behind. Reason for that is the fact that this character is made for my project. I’ve got it to this level to ensure good gameplay. Also for one of them…not gonna lie, I just couldn’t figure out how to handle. I’ll mark the “to do” things at the bottom, and will be updating this post with every bigger change.
Here’s a video to demonstrate:
The changes shown here include:
- Forbidding actor orient to vector on walk backwards;
- Setting a special animation to walk backwards;
- Linking the head and neck bones to the controllers pitch and yaw to make the head follow where you’re looking;
- Limiting the head turn angle when standing still (so you wouldn’t break your neck).
Camera Position
One of the first and the most obvious things to do was to properly align the camera to the head. It wasn’t a hard thing to do, but required some thinking. First of all, the camera should sit on a position where it wouldn’t see inside the body, no matter the angle or animation. To get that I’ve set it a tad above the head itself. Realizing I still need the camera boom, I’ve shortened it to keep it from coliding and attached it to a socked I placed on the head. The attach wasn’t required, but I did it so the camera would have the same transition animations as the head does, thus look more classy.
Walking Backwards
A. Forbidding Turning Around.
Now stopping that son of a gun from rotating 180 whenever I pressed the go back key was a real jam, especially for a junior IT student, fresh with UE4.
I started from the event graph where placed a branch to determine if the player has decided to move backwards. As the condition I’ve set the Input’s Axis Value being bigger or equal 0.
Now the Axis Value of the turn would go below 0, that means the player just punched the keys responsible for the player to go straight back. What this does is sets 0 to a custom Walking Forward variable (explained later), switches from orienting the rotation to movement to using the controller rot yaw. Thanks to this, when the back key is pressed, the player would not turn around, and its rotation would fit the yaw of the controller (left-right movement).
If the Axis Value is above zero the script basically returns it to the default state.
B. Walk Backwards Animation
Now that the character was politely staying in rotation I needed to do something with the animation to make sense if while going back, the player would look down.
For that I duplicated both the walk and run animations, and changed their rate to -1
After that I made a new blend space, where instead of the popular 0-375 axis range, I went with (-375)-375 (I’m a rebel). Easy to figure out what happened next. The -1 animations went on the minus sides proportionally to the ones on the plus side.
With that behind me I quickly set the blend space as current for the actor, and went on with a script, telling when to use the negative animations, and how much.
In the animation blueprint for the character I’ve found the spot where the value of Speed gets assigned from some vector stuff.
Here the Walking Forward boolean was born. I’ve set the branch before the set speed working on the Walking Forward bool as its condition. If the character is NOT walking forward (bool = FALSE) the value assigned to Speed would be the opposite *(-1)] to the vector length.
So now. If the Inputs Axis Value is smaller than 0, the value of Walking Forward would automatically change to 0, which results in assigning an *-1 value to speed. Thanks to this the player neatly walks back, when he’s moving backwards.
Head Rotation
Since I’ve always been a detail freak, it caught me straight at the beginning that if the head of the character’s head wouldn’t move with the camera it would look really stupid. Even if I didn’t have any mirrors in my game it still would seem odd looking at your shadow and realizing that the head is static.
Now here comes the real crazy!
So I’m gonna be honest with you. When I got my self to finally fix this I’ve no **** clue on how to do it. Took about 3 hours of research to get any basic idea on what should I look into.
I’ve found some neat info on transforming the individual bones in the anim graph and that I could even rotate them by a custom rotator.
That was the stuff…only incredibly hard to figure out somehow.
I started from writing a basic script in the animations event graph that would give the rotation of the control rotation to a custom rotator named Head Rotation. Then I’ve set a basic Transform (Modify) Bone for the head bone in the anim graph. The efect was ok…sorta…pretty much no. The head did move with the mouse, but kept getting messed up when I moved the body.
Took me 2 hours to figure out why. Tried milions of different ways, and ended with nothing. Then I recalled the words of my high-schools math teacher:
So, not really knowing what delta rotation does in practice I tried it with the Actor and Control Rotation…And it bloody worked!
It did take a few more edits, here and there, but I ended up with a nice, neat working script.
Now for some reason the axis had to be switched but the effect was ok. I also slowed down moving the head sideways for nice purposes.
If you look closely, you can see that now there are two custom rotators: one for the head, and one for the neck. The reason is cosmetic.
After a bit of playing around I’ve realized that having the turning sideways done by the neck, and turning up/down by the head just looks better.
The Anim Graph was simple to set up.
As you can see, I have two separate modifiers with two different rotators.
Both use the same settings:
- Everything disabled, but the rotation.
- BMM Additive
- Parent Bone Space
Can’t remember 100% if using other options works, and at this point I’m afraid to try, but quite sure only those give the good results.
Anymemes, after about 5 hours of yelling at my computer I have finally made a ready, neatly working script which turns the head wherever the player is looking at.
Limit Head Turn Angle
The final thing I wanted to take care off is the fact that when standing still, the player could turn his head 360 degrees around his body. Easy to figure its quite unnatural for humans, even if my character would be a robot in his (not so) bright future, I had to take care of that.
Using again lots of print strings I’ve found a nice degree (that’s how you call it?) between which I’d like the player to be able to turn his head.
In order to make the rotation of the head have its zero in the middle angle of the body I again had to use a** delta** from the actor and controller rotation. When I had that, I’ve set up a few logic rules.
So what we see in the first part is branch #1 with a condition. This branch is true only if the delta Yaw is a value between -120 and 100. If this is true the branch sends you directly to the Add Controller Yaw Input.
If the branch is false tho, it’s getting a bit more complicated, since without any additional elements on FALSE, the camera would simply stop moving. So I needed something to take care of this problem.
First of all I had to find out where the camera is stuck blocked at: right side, or the left side. For that I made a branch #2 which is true if the yaw is bigger than zero (looking left), and false if smaller than zero (looking right). Having this information now I had to tell the engine that if, lets say the head is blocked on the left side, and the player moves the mouse to the right than it’s fine, you know, let him move the head bro, and vice-versa.
For that I used two branches (#3 and #4) which as condition take not the delta, but the input axis itself. Now if the axis wants to rotate the head the opposite direction the head went before it was blocked, than the movement would be allowed.
I’ve also set up a small limiter on the pitch, to stop the player from looking all the way down.
So basically a nice little limiter. I can bet a lot of money that there’s a much easier way to do it, but if works for me, so meh.
I won’t show setting up sprinting here, because it’s really easy, I mean c’mon.
To Do List
As I mentioned, the player still has few things that I need to do with it.
Fortunately I think I’ve covered the most pain in the butt elements, and the rest won’t be so hard.
For now I’m happy with the player model, especially since for most things I needed, tutorials were barely findable, and answerhubs rarely could help the problems I had on the way.
The number one thing I need to take care of is to stop the player from turning his body around the wrong direction sometimes, when the camer would look to the right, and I’d decide to turn him around to make the body face it. For now tho I have no idea on how to make it, so if you have a vision about this, please let me know.
I’ll also have to fix the clipping at some degrees, but that’s a cosmetic.
Now I gotta work on some level design for my big project (the character is a part of it), and afterwards I might get to fully fixing the details on him.
Thinking of starting a devlog here on it. Might be fun.
But anyways, thanks for reading. Hope it helped and sorry for my English.
Have any questions/tips leave them here.
(5 hours of writing…well, ****)