How to create a camera that zooms & pans to follow 3 co-op characters?

danimations

Member
Hi all.

I'm working on a top-down 3P co-op prototype in GMS2, and want the camera to:

1) automatically zoom in/out and pan with the 3 characters
2) keep all three characters on screen at all times

I set up an invisible object at the mid-point (x coord) of the three players, and am tracking that with the camera... but when players spread out, those characters disappear off the screen.

My rooms are wide, but not deep... so it's only the horizontal borders where I "lose" the characters.

I would like the camera to zoom out as the players spread apart. Any advice would be warmly received! :D

Thanks in advance!

In this discussion thread, commenter Derek suggests "assigning" multiple objects "to a parent" then following that... is this advice applicable in GMS2? https://yal.cc/gamemaker-view-following-two-objects-at-once/
 
Find the center of the charectors using.
GML:
 xc = (player1.x + player2.x + player3.x) /3
 yc = (player1.y + player2.y + player3.y) /3
And then find the distance between the two ferthest
GML:
xd = max(player1.x, player2.x, player3.x) - min(player1.x, player2.x, player3.x)
yd = max(player1.x, player2.x, player3.x) - min(player1.x, player2.x, player3.x)
And then, since you dont want to stretch your view, simple use x or y distance depending on wich is bigger.
 
Top