How would you handle cameras here? (Camera snapping between mulitple nodes)

Hi everyone! I am currently prototyping a game idea and need some advice on how to handle changing cameras between two nodes. Below is a quick demonstration of what I have so far:

camera_tweening_issue_short

(The placeholder pixel art is not my own, it was obtained from a tutorial I followed.)

Each of the nodes has its own Camera2D. The player can swap which node is active, and when the node activates, the camera of that node becomes the current one.

However, this is super jarring, so I tried to smooth out the transition between cameras using tweens. But, for some reason, that only works once. Below is the code that should handle it.

func update_camera(prev_position: Vector2) -> void:
	# Sets the camera to the position of the previous node's global position, 
	# then tweens to the origin of the node. 
	camera.position = prev_position - self.global_position
	camera.make_current()

	tween = create_tween()
	tween.set_parallel(true)
	tween.set_ease(Tween.EASE_OUT)
	tween.set_trans(Tween.TRANS_CUBIC)
	tween.tween_property(camera, "position", NODE_ORIGIN, 0.8).from(camera.position)
	tween.play()
	await tween.finished
	camera.position = NODE_ORIGIN

It only seems to work properly the first time the node is activated. Any subsequent times, the camera does this weird springy thing, and I cannot figure out why.

Now, my question is, how should I handle the camera here? I’m questioning whether it’s even a good idea to move the camera to center on the player. The game that inspired it I believe just moves the camera when the player is close to the edges of the screen. But, there will also be platforming, so I want the camera to follow the player if in “platforming mode”.

Also, will it affect performance greatly to have so many cameras in the scene? I learned the hard way that reparenting is not the way to go about this, but is having a bunch of cameras for each node a player can jump to too far in the opposite direction?

Thank you for any advice you can provide!

I recommend you check out the Phantom Camera plugin.

I used the tutorial here and it worked like a charm! After giving it some thought, moving the camera by zones I think is the way to go.

Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.