Making a camera follow 2 objects at once

I would like to make a camera that zooms in an out if 2 players move away or closer to each other.

Best way to implement something like this is to add a new Object Sprite to act as camera tracker so you center the camera on that tracker and set the tracker position distance between the two players depending on your needs so then

Check if p1 and p2 and tracker distances is > or < xxx do stuff… apply zoom or move the camera with lerp or whatever you want to do.

What would be the best way to make the tracker stay between the players?

Use Advanced function to compare two numbers so this way you can get the distance between p1 and p2 once you get the distance just divide by 2 and set that value to the X of the tracker.

Take just one of the players as a starting point for the tracker.

Easier to add the X positions of the two objects and divide by 2. Same for the Y positions. This’ll give the mid point between the two objects.

pseudocode : cameraFocusObject.X = (obj1.X() + obj2.X()) / 2

What action would be used for this? Just “Change the x position of the center of the camera”. Not really sure what “Advanced function” means and how to use it.

Yes, and similarly for the Y position of the camera.

Would this be the camera tracker? The object that the camera follows that’s between the 2 objects?
Any how I try I get these same erros.

  • I fixed the space at “() )”

You’re mixing up a few ideas in one command. We’ll use the one where the camera follows the camtracker object. You’ll need 2 actions, and they can be part of the same event :

  1. set x position of camtracker to (Dile.X() + Lori.X())/2 (do the same with the y position), and then
  2. Centre the camera on camtracker

ah, that explains it. Many thanks to both of you : )

To confirm, it should look something like:

I did it in a more primite style but I will update it. Can I ask for a bit more help? I would like to camera to zoom about when the players get closer and farther apart. Would you happen to know how to accomplish this? vsa
*I realized I did it quite differently.

  • My method did not require the camtracker.

No need to change it - it is an alternative way of achieving the same result. Both ways are correct.

I’d say it would be a calculation involving the screen resolution and the current distance between the 2 objects. If someone else doesn’t come up with a solution, I’ll give it a shot in the morning (it’s quite a bit after midnight right for me now, I need my beauty sleep :slight_smile: ).

1 Like

Alright. I will be waiting and trying it out with my knowledge base. Thanks a bunch for all your help!

Here’s a camera zooming solution. I started it as another thread, so that it could be more easily found by others searching for the same thing.

1 Like