How to clamp when using AddRelativeLocation?

I’m using AddRelativeLocation to adjust a pawn’s Z height, but I don’t want the Z height to go above or below a certain value.

The only examples of clamping rotation I see are ones using setRelativeRotation or something similar. Is there anyway to clamp the Z while still being able to use AddRelativeLocation?

You don’t need to use ‘AddRelativeLocation’ if you just store the location in a variable, and just add to that variable (clamp while doing so), and then set the world location to your variable.

Updated and working with advice Jamen gave in the post below:

There is a more “Logical” way to do it. You are adding location, and then setting it to a clamped value (You are setting the location twice for the same thing, it even took me a second to figure out why you were doing what you did). You should subtract 100 from the z on that break vector, and then just throw out the ‘AddRelativeLocation’ node altogether.

I was on the right path, thank you. I posted the new screenshot with your advice in the post above.

One last question if I may :slight_smile:

I want to use **add movement input, ** because it uses the **FloatingPawnMovement **component features. I’m currently clamping where the camera object is allowed to go, but I don’t know how to get that same logic to work with add movement input.