How to move between two cameras smoothly?

lonskynelonskyne Posts: 7Member

I have two players that I can both control at the same time. Both are separate and each of them has a Camera2D node as its child. I typed some code so I can change between cameras (the two players) with a button press (disabling the current for one and enabling for the other) and it works but I want to make it smoothly scroll to the other player and continue following it after it stops. How would I do this, this is a 2D platformer. Thanks


Tags :

Comments

  • MegalomaniakMegalomaniak Posts: 1,828Admin

    Use only one camera and have some other objects parented to the players as location trackers, then lerp the camera location between those two?

    This would make the camera it's own entity in the scene effectively. Not parented to either player and free to move on it's own.

    Or you could just create a third camera for the transition and just switch to it in-between the other two.

  • lonskynelonskyne Posts: 7Member

    @Megalomaniak said:
    Use only one camera and have some other objects parented to the players as location trackers, then lerp the camera location between those two?

    This would make the camera it's own entity in the scene effectively. Not parented to either player and free to move on it's own.

    How would I get the smoothing effect of the camera if it's not a child to either one of the players?

  • cyberealitycybereality Posts: 539Member

    The basic idea is to create a third camera on the root node made just for transitions. When you want to switch cameras, set the transition camera to the active camera's global position and rotation, switch the 3rd camera to active, then use a tween to interpolate the transform. When the tween is done switch to the second camera. Hope that helps.

  • MegalomaniakMegalomaniak Posts: 1,828Admin

    Right, Tween is probably the better option indeed.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file