How can I make the camera follow multiple (more than 2) players and zoom in and out when distance is close or far?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dragon

Me and my friend are making a game and it has multiple characters, one thing I’ve been trying to figure out for 2 days is how can I make the camera be in between multiple ( more than 2) characters and zoom in when they are close to each other and zoom out when they are further away. It is like a fighting platform game where multiple characters survive by killing one another, it’s kinda like smash. But how do I get the camera to do all that?

:bust_in_silhouette: Reply From: Dumuz

The first thing that pops in my head is to use the distance_to() method between all the characters and then base the camera distance off the characters that are furthest away.

Something like:

func _process(delta):
	var A = Player1.distance_to(Player2)
	var B = Player1.distance_to(Player3)
	var C = Player2.distance_to(Player3)
	var far_characters = max(A,B,C) 
	Camera.look_at_from_position(Camera_position * Vector3(1,1,far_characters), target_look_location, Vector3(0,1,0))