GameMaker: View following two objects at once


This example is going to be of great use for everyone making local multi-player games, as well games requiring to display two objects on screen at once generally.
Effect here is, that view is positioned and scaled (if needed), to include two given instances at once.
Example provides a single function that does this sort of trick for you, absolutely painlessly and easily.

Download GMK

Related posts:

21 thoughts on “GameMaker: View following two objects at once

  1. Hello Vadim!

    Great work on the multi follow system. My tiled assets are tearing, what looks like every 200 pixels or so, when the camera zooms in and out. Any idea how to fix this? Is it a problem with drawing X and Y coordinates that are not whole numbers? Thank you!

    • You’ll have to import it into GMS 1.x first, and then import the GMS 1.x project into GMS2. Or study the manual to rewrite everything to use camera systems instead of views.

      • I tried to rewrite it but i was having trouble with the scaling and I cant import into studio 2 I only have the trial

        • I also tried making both the objects a parent of another object that i had the view follow but the view just follows one at a time.

  2. Thanks fo this example! It really helps me out.
    But, do you know of a way to limit as how far the view can travel beyond
    specific x, y, w, h coordinates?
    I’ve tried tampering around a bit, and I just could not find an answer to it myself.

  3. Thanks so much for this example! Really helpful! One question: how would I go about adapting this to add a maximum view size? I want it to be able to zoom out to a maximum level at which point the player could leave the view. I just don’t want it to infinitely zoom out

    • You would need to add another line to view_dual after “vscale” setting to limit it, such as
      vscale = min(vscale, 4)

      • This is a great piece of code. Thanks for the share!
        I’m trying to use it to track an object starting at the top of the room and falling down to the ground with the other object being invisible and sitting still on the ground. I’m using the second object like an anchor so as to make the view start zoomed out (when the 1st object is at the top of the room) and as the object falls the view zooms in until it reaches the ground.

        My question is this: Does anybody know how to make it so that the view doesn’t show outside the room at the top and bottom? So if the object would launch off the ground and head upward (away from the second object) the view zooms out so as to ‘track’ both objects (basically I want the view to stop zooming out if it is going to show outside of the room)

        • Aw man! I just realized “khaag” asked the question that I’m looking for the answer too. YellowAfterlife you answer said this:
          You would need to add another line to view_dual after “vscale” setting to limit it, such as vscale = min(vscale, 4)

          So is this what you mean:
          vscale = max(1, abs(x2 – x1) / (vw – vb * 2), abs(y2 – y1) / (vh – vb * 2));
          vscale = min(vscale, 4); (<– ADD THIS LINE HERE is what you are saying)

  4. Hi, sorry for writing on an old article, but how would I go about following four objects at the same time?

Leave a Reply to LurkGames Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.