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
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”):
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 :
Play timeline
Get the Camera Distance value from the timeline
Get your “Normal camera zoom value” from your camera/controller/pawn/whereever you put it
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 :
Play timeline
Get the Camera Distance value from the timeline
Get your “Normal camera zoom value” from your camera/controller/pawn/whereever you put it
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 :
Play timeline
Get the Camera Distance value from the timeline
Get Spring Arm, set target arm length equal to the value of the Camera Distance float from the timeline
OnActorEndOverlap :
Play timeline in reverse
Get the Camera Distance value from the timeline
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.
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.
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:
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.
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
Get the spring arm
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.
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?