Change 2D Camera distance dynamically

I’m trying to change the distance of the camera using the 2DSidescroller template. When I enter a certain area (via a trigger) the camera distance (which I defined via Target Arm Length of the camera boom) should change and when I leave the area it should revert to the original value.

This doesn’t work, nothing happens when I enter the trigger in the level

https://i.gyazo.com/b4059b6513c648ed25a2e5487f09c3c8.png

I don’t get what I’m missing. I tried several ways but apparently the issue is at the end where I define the new values.

I haven’t tried the template myself, but from what i can see the following is happening:

OnBeginOverlap : The timeline starts and for each timeline update the spring arm distance gets increased
OnEndOverlap: The timeline starts and for each timeline update the spring arm distance gets increased
You see what the error is? Regardless whether you go the timeline normal or reverse, you coded it so it increases the camera distance, but never decreases it.
You also ignore the ouput of the timeline (i assume the float output is the desired camera distance?).

First solution:
If you only want the timeline to represent some distance offset from a normal camera lengh (like, having the Camera Distance in the timeline go from 0 to 10000 to give a zoom-out effect compared to “normal zoom” or from 0 to -10000 to give a zoom-in effect compared to “normal zoom”):

  1. In your camera or player controller or character, add a “Normal camera zoom value” float with some default value (say, 10000) and set the arm length as that on camera/player controller/character construction
    OnActorbeginOverlap :
  2. Play timeline
  3. Get the Camera Distance value from the timeline
  4. Get your “Normal camera zoom value” from your camera/controller/pawn/whereever you put it
  5. Get Spring Arm, set target arm length equal to your “Normal camera zoom value” + the value of the Camera Distance float from the timeline

OnActorEndOverlap :

  1. Play timeline
  2. Get the Camera Distance value from the timeline
  3. Get your “Normal camera zoom value” from your camera/controller/pawn/whereever you put it
  4. Get Spring Arm, set target arm length equal to your “Normal camera zoom value” + the value of the Camera Distance float from the timeline

Second solution :
Alternatively, the timeline is the normal desired camera distance outside the area (say, 40000) and the end is the desired distance while inside that area (like, 100000)
OnActorbeginOverlap :

  1. Play timeline
  2. Get the Camera Distance value from the timeline
  3. Get Spring Arm, set target arm length equal to the value of the Camera Distance float from the timeline

OnActorEndOverlap :

  1. Play timeline in reverse
  2. Get the Camera Distance value from the timeline
  3. Get Spring Arm, set target arm length equal to the value of the Camera Distance float from the timeline

if the timeline float outputs are too small (aka the zoom out/in is too insignificant), you can, after getting the Camera Distance float from the timeline, first multiply it by some factor (say, 100 or 1000) before setting it as the new arm length to increase the zoom distance… Alternatively, you can just adjust your timelines “Camera Distance” values so you don’t have to do this multiply-stuff. :slight_smile:

The first solution is probably good if it is possible to have multiple timelines active at the same time, aka overlap/endoverlap several areas in a short timeframe. The second solution would have some wierd results, but i listed it anyway incase you want to hardcode your camera distance soley based on the timeline. So my suggestion is to use the first solution.

Thanks for the response.

At first I tried using another solution without the timeline which didn’t work either. Basically I want to increase the arm length 3000 units (the cam distance float is currently the max. value I want, 5000, the default distance I defined in the properties of the SpringArm is 2000)

Now I have absolutely no clue what nodes I need to get point 3 of your idea working though.Could you elaborate more in detail? I usually don’t code and we’re jamming here and running out of time so I thought I could help out with some basics.

I also failed using other solutions without a Timeline component. I don’t get what he needs more when I use the Target Arm Length to the Camera Distance and as target the Spring Arm.

So you have some actor that has the camera arm and thus access to the arm lengh, right?
In that actor, add a variable called “DefaultArmLenghValue” of type float with value 2000.
That determines the default zoom value/default camera arm lengh of your camera system

Then do the following:
Either in your construction script or your beginplay script of that actor that’s holding the camera, get the arm length and use “set target arm length” with the mentioned default “DefaultArmLenghValue” value. So when the game begins, the arm lengthj is set at 2000 by default.
Or simply set the default arm length to the same value as the “DefaultArmLenghValue” float. Your decision, doesn’t matter, the important thing is that now we have a default arm length value that we can always have access to and that the arm length value gets adjusted to that value on game start.

For step 3:

  1. Grab the “Camera distance” output node from the timeline, drag it and add a “float + float” node. One input of that node is plugged in by that “Camera distance” timeline output.
  2. In the other input to the “float + float” node, plug in your “DefaultArmLenghValue” float value
    Now we get a value that is “DefaultArmLenghValue + timeline value”, aka standard zoom value ± some offset
  3. Get the spring arm
  4. from the spring arm, use the node “target arm length” and as “target arm length” plug in the output value you get from the “float + float” node.

Thanks for the detailed explanation.

What I now have is this:

https://i.gyazo.com/0111f836dcd76257ff9074eeab67e428.png

I still doesn’t work

I put the value from the “Default Arm Length” in the value ranges (?) - tried both equal numbers (so 2000 / 2000) and the 2nd number different, didnt change

However I constantly get this error for the camera arm var I created in the first place on runtime (this happend throughout everything I tried) so I assume there is something wrong there as well?

https://i.gyazo.com/dc9f27d9b632c299d4fa1b10979d45da.png

This is the var:

https://i.gyazo.com/2821bbbdf31bd3ab78bd2395411249b4.png

and I got it from the default 2D character blueprint: https://i.gyazo.com/e8d3bf46e101df95ba23f244096c1316.png