Setting a max and min height for camera pawn

Hi!

I am working on some sort of a strategy game and I am just starting with the basics.

I’ve made a pawn for my camera with a floating pawn movement component and add some movement code to it, but I have a problem with zooming.

I can zoom in and out normally and can’t exceed the min or max height, but the problem is when I reach the min or max height, the camera does some sort of bouncing or vibration and it moves forwards or backwards.

I am saying in the code that if the height is more than max, then set it to max. If it’s less than min, then set it to min.

Any ideas?

Hi,

I don’t see anything bad with your logic but instead of setting the position back to the min/max manually, have you tried using the Clamp node?

Same thing here. It has the same bouncing effect when it reaches the min or max height.

Hi,

Could you please post a screenshot about your setup?

OK, here you are.

I know, very untidy, but I leave tidying and grouping repeated things in functions after I get some working code.

Hi,

I think the problem MIGHT be that every time the True part of the Branch node is executing it adds a movement input which might exceed your min/max range, but you only have a chance to set it back in the next frame when the False part is executing, so there might be some fighting going on. But this is just an idea I am totally not sure.

What I would try is not using AddMovmentInput, but some other setup to move the acor, making sure that the new location value is clamped BEFORE you use it as an input, this way you can prevent the value to ever exceed your limit, so you don’t even have to set it back.

Thank you so much. Here is my working blueprint.

I just have one more question: how does AddMovementInput work? I mean what is it multiplying the scale value by?

Hi,

The scale value comes from the player. In case of a button, it can be either 0 or 1 depending on if the button is pressed. 1 means 1 unreal unit, so if you multiply the scale value (Axis Value) by 10 and plug it into your AddMovementInput node, your actor will move 10 unreal units each frame.

But I have noticed something different.

What you are saying is that If I have a scale value of 0.5f, the actor will move 0.5 unit, this means that it will be equal to my blueprint above without multiplying it by MaxSpeed and that’s not right.

What I wanted to know is in the internals of AddMovementInput, what does it multiply the axis value by and how it applies the movement.

Hi,

Now I got a little bit confused. I will try to explain what I mean and I hope that will answer your question.

When an Input Event executes (like your InputAxisZoom) it will give you an Axis Value which can be either 0 (not pressed) or 1 (pressed) in case of a keyboard button.

The AddMovementInput node offsets your actor in the World Direction you have provided by the Scale Value every frame (well, if you execute it every frame, but if it is hooked up to an Input Event, you probably are). So every frame your actor will move in the World Direction, 'ScaleValue" units. This means if you plug your ‘AxisValue’ without any modification into the ‘ScaleValue’ your actor will move 1 unreal unit in the ‘WorldDirection’ each frame, while the button is pressed.

Multiplying the ‘AxisValue’ by any number (like 0.5) and then plugging it in the ‘ScaleValue’ should indeed cause the node to offset your actor by 0.5 unreal unit per tick.

I hope this is what you mean, if not, I’m really sorry, just clarify what you want to know and I will try and help.

OK. Thank you. I just wanted to know the speed by which the AddMovementInput multiplies the AxisValue, but it’s not really that important.

Thanks again

Hi,

I think you might misunderstand it. It depends on YOU!

Look at your first screenshot! You plug the Axis Value straight into the AddMovementInput node, so you do not multiply it or change it in any way, therefor it will be 1 when the button is pressed, so you move your actor by 1 unreal unit/frame. It is 1 because the Axis Value of a keyboard button input can only be either 1 or 0, nothing between.

Now let’s say, before you plug your axis value into the AddMovementInput node, you multiply it by 2. This way your actor will move 2 unreal units each frame and so on and so on.

Basically, the float value that is plugged into the ‘ScaleValue’ input of the AddMovementInput is equal to the unreal units that the actor will move a frame. It doesn’t matter where that float value ‘came from’. If you would type in 10 (so not plugging anything) it would move the actor by 10 unreal units.

I really hope this anwers your question, otherwise I’m pretty much lost about what you mean :smiley: