Topic was automatically imported from the old Question2Answer platform.
Asked By
Leoseverini
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()
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. The code you shared also makes for a good example of how how to use the tweening node.