Translation between 2 cameras2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Leoseverini
:warning: Old Version Published before Godot 3 was released.

Hi I have 2 objects with 2 cameras, each object is in a different location.
When a even happens I go for a moment to the second camera and return to the first one.
Now I want to make a better translation. Make that the first camera goes to the second object and return and make a zoom out and in at the same time. Like google earth when you change the location.
How can I do it?

Thanks

I solved using camera offset.
Get the first and second object position, make the difference and with the tween I made the translation
Also I changed the Zoom of the camera to make a good animation.

Here the code

var tween = get_node("Tween")
var player = get_node("Player").get_pos()
var playerPos = player.get_pos()			
var doorPos = get_node("Door").get_pos()
var diff = doorPos - playerPos

tween.interpolate_property(player.get_node("Camera2D"), "offset", Vector2(0,0), diff, 2, Tween.TRANS_CIRC , Tween.EASE_OUT)
tween.interpolate_property(player.get_node("Camera2D"), "zoom", Vector2(1.4,1.4), Vector2(0.8,0.8), 2, Tween.TRANS_CIRC , Tween.EASE_OUT)
tween.start()	

Leoseverini | 2016-10-21 20:00

:bust_in_silhouette: Reply From: eons

Point A to point B with a zoom out, like moving in a parabola?

The first thing that comes to my head is:

  • Create a third camera that takes the parameters of origin camera and set as current.
  • Animate the third values to the values of the destination camera.
  • Add a zoom track with far zoom on the middle.
  • Select a good interpolation for a slow motion effect on the high zoom part.
  • And, of course, set the second as current

Thanks for you answer.
Is a good idea but I solved it using offset of the camera and Tween.
I think is simpler

Put the answer in my question.

Leoseverini | 2016-10-21 19:56

Nice solution, is a good example on the use of tween.

I have not used much tween yet (I like to save and recycle animation resources) but seems less buggy than the AnimationPlayer.

eons | 2016-10-22 18:39

:bust_in_silhouette: Reply From: avencherus

I can’t think of why you need two cameras if you plan on moving between two focus points. I would just use one camera, and then in GDScript, interpolate it’s position and adjust it’s zoom according to the distance. Tweaking it until it looks how you like it.

Is exactly what I did.
At first I had 2 cameras, and switch them
Now I have only one, and using offset and tween, made the tween.

Leoseverini | 2016-10-21 20:14

Good work. :slight_smile: The code you shared also makes for a good example of how how to use the tweening node.

avencherus | 2016-10-21 20:23