How to do a Lean in/out Feature

Hello,

I’m trying to get a simple lean in/out which allows the player look around corners. Does anyone know how to achieve this type of effect?

I’m currently using ‘True Fps’ in the third person blueprint.

Many Thanks
Mrfantasticghost

Hi Mrfantasticghost,

I have been working on this myself and here is what I have come up with:

I set all of the origin variables to Default to the same location/rotations as the components are initially. You can get those from the Components view.

I use a timeline so that it’s a smoother transition. It would be very simple to do just and Add Local Offset, but that causes a noticeable jump. The timeline curve is just two points (0,0) and (.3,1). It is just driving the Lerp Alpha.

The Arm Location and Rotations are not needed, but I added them for effect.

Let me know if this helps.

Hey

Thanks everything worked out great!!! :smiley: I just added a clamp after Make vector node and adds a limit how far the camera goes. Thanks for all your help man

Many Thanks
Mrfantasticghost

Just a quick question. When I’m holding the button its seems that the timeline plays multiple times, making it last longer when I release the button. How do I prevent this, so when the player releases it the its snaps back to the original position straight away?

Do you have the timeline set to looping? You will want it to be set to only play to the end. If that doesn’t help, can you please send a screenshot of your blueprint and some more details about what is happening?

I figured it out haha, the problem is that the timeline was playing over and over again when Q was held down. Just checked Use last Keyframe tab in the timeline and now it returns back to the original position of the character when Q is released!! :smiley:

That’s good to hear. I’ll mark this as answered then. Have a great day.

Hi,

I am new to Unreal engine and trying to learn and understand this. Can you post the timeline or mention what kind of graph it is in the timeline?

Also I’m trying to implement this lean function in the FPS template as I am aiming to make an FPS game but am wondering whether it is best to go third person template instead as it sounds like the Third Person template is still a better base for a FPS game. Any thoughts on this?

If it is best to stick to an FPS base, can you assist on explaining what I need to do to modify that solution you have above? I tried implementing it but can’t find a number of items such as “arms”, “first person camera” (I have first person component though), “camera lean origin”, “arm rotation origin”, “arm location origin” and the set relative location and rotation seem to be set to actor rather than scene component.

Thanks in advance and really appreciate the help if you are able to as I can’t seem to find many lean examples, perhaps it is a feature dying out in fps games…

1 Like

I can clarify some of this, let me take a shot.

Can you post the timeline or mention
what kind of graph it is in the
timeline?

Float Graph. The timeline curve is just two points (0,0) and (.3,1). It’s a straight line with no Bezier.

it sounds like the Third Person
template is still a better base for a
FPS game. Any thoughts on this?

Only if you wanted a game that could switch camera angles. If you want a pure FPS, you would end up importing and modifying a lot of stuff for no good reason.

I tried implementing it but can’t
find a number of items

“Arms” are the FPS template Skeletal Mesh arms. I was working out of an FPS template for this, not a third person.

I set all of the “origin” variables to Default to the same location/rotations as the components are initially. I did that by setting them in the Construction Script.

set relative location and rotation
seem to be set to actor rather than
scene component.

You need to drag off of a Get of the Component to get a context sensitive node that will work on components instead of the whole actor.

Let me know if you have any questions.

Hey good shot! Your explanation was great! Had to work it out a bit but that’s because I am new to this.

I got the lean left to work now and it works so well! But I have this odd issue now where my camera height seems to go down permanently to what it feels like the crouch position after using the lean. The odd thing is that it doesn’t go down any further if I were to use the lean again. Instead it works without any glitches. The only thing is that the height never returns to normal regardless if I jump, crouch or shoot. It’s like leaning has turned the player to a dwarf!

I’ve attached what I’ve done in the construction script and event graph, could you see where I’ve overlooked something? I checked a few times and can’t seem to pick up where the mistake is. I assume it’s to do with the camera origin taking in a new value but releasing should reverse all of this?

Once again thank you so much for helping, this is the only thread that I’ve found with a lean solution.

Oh, you’re using VR head tracking? In that case, I have 2 notes:

  1. You will need to reset those variable when you realign the HMD location (this is probably where the offset is occurring). So in the Event Graph you will want to set them whenever you do a HMD location adjustment.
  2. Any time you force head movement in VR, you run the risk of inducing motion sickness in your player. I would suggest just letting the head tracking in the device move the head uninterrupted.

I hope that helps, let me know if you have any questions.

Looking at your Event Graph, I just noticed that the Lean Timeline needs to be plugged into all of the Lerp’s Alphas. Let me know if that helps with it

It works! Thank you so much!

I was really confused with the part of the VR head tracking as I thought to define those origins I had to retrieve the values from somewhere so the only place I could grab them was that “Get Positional Tracking Camera Parameters”. But after re-reading what you wrote earlier “I set all of the “origin” variables to Default to the same location/rotations as the components are initially.”, I realized you meant manually look them up and set them which made the construction script a lot simpler.

After correcting the mistake with the missing links from the Lean Timeline (Good eye by the way!), the lean works with no problems.

But if you can help me just understand this further as I have built the lean right part. I realize I would need to reverse the subtract and add blocks for the camera and arms? I found that lean right seems to work fine if I only switched the subtract block with an add block for the First Person Camera only. Would there be something wrong with this if I didn’t reverse the other add and subtract blocks for the arms rotation and location?

You would see the camera lean in one direction, but the mesh of the arms would tilt in the other direction. It wouldn’t hurt anything, but it would be visually a little confusing.

Yeah that’s what I thought logically but it seemed to work. Maybe I was a little tired and didn’t realize the animation was going left rather than right. Anyway I implemented it with arms as well now. Thank you so much for guiding me through it! Now off to do prone and figure out how to work the targeting in.

[Part 30]-Leaning Mechanic- How to make an advanced FPS game - Unreal Engine 4 - YouTube There you go! Full tutorial

Hello there I have done a similar feature using a transform modify bone. Works for first and third person can also be replicated. You create a simple custom event that has a float input. Then create an input for which key you want set it between 35-45 for the float when pressed then 0 when released for right lean then -35-(-45) for left input pressed. Then in your anim graph do a split struct for rotation on the transform modify and plug the lean float you create in your animBP that you set there pretty much copying the one used for your input function from your player character bp. Lerp it set the target whatever your variable from your character is. Use whatever time you want it to take I use 4, then the output is your variable in your anim Bp that you call at your transform modify. Only issue I am having is the players spine rotation is conflicting with the lean spine rotation when looking up and down maybe I can not use the same bone in the sun offset as I do with the lean. The lean only affects the pitch.