A Camera That Would Include Two Objects Moving Apart?

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I need help in making a camera that would follow between two objects moving apart from one another, include them in the display, and yet not show anything beyond the layout.

    So far, with the use of the AdvancedCamera plugin (version 0.92b) and ShadeKirby500's help, the camera zooms out to include the two objects (in the case of the example I'm about to post, two objects with the 8-directional behavior; the actual game I'm working on will use two objects with the platforming behavior, but I digress); however, it zooms out to include things outside the perimeter of the layout, which is not what I want.

    Here is an example I created to show how the camera behaves right now, and here is the AdvancedCamera plugin, version 0.92b (I don't feel like finding Linkman's original link).

    The meat and potatoes right now are in the Always event under the Layout1's event sheet. The camera's zoom is set in both the x and y axis as,

    clamp((DisplayWidth*(3/5))/abs(distance(PlayableCharacter1.X,PlayableCharacter1.Y,PlayableCharacter2.X,PlayableCharacter2.Y)),0,1) * 100[/code:r4oo0a5r]which sets the zoom to a ratio from the inclusion of 3/5 of the display's width in total between the two objects and their respective sides (which right now is a margin that is 3/5 the display's width for both objects) to the absolute distance between the two objects.
    
    This formula for the zoom was created by ShadeKirby500, and I'm supposing with an educated guess that the second value in the clamp expression (b in "clamp(a,b,x)") would be the maximum zoom restriction.
    
    Again, I'm supposing that that only fixes the total zoom, not the margins between the objects and the layout borders... which should decrease to zero once they reach the boundary of the layout.
    
    Any help would be greatly, greatly appreciated... I've been at this with unsuccessful trials and errors for days now, along with the help of my real-life friend (with whom I'm making the aforementioned game with), ShadeKirby500, and Pixel Rebirth.
    
    ... Please?
  • Well, let's start with the good news:

    Here is a cap working the way you want.

    The bad news:

    It's much more complicated. Of course the cap isn't optimized, but even then it needs a lot of expressions, because there is a lot you have to keep an eye on.

    I try to explain from the beginning, but feel free to ask if I'm not clear enough.

    (1)

    Most important is understanding, that you will see parts outside of the layout's boundaries when completely zoomed out, if the aspect ratios of the layout and the display don't match.

    Your layout is 1800x1200, that's an aspect ratio of 1.5 (or 3:2), but the display was 640x480, which is 1.333... (or 4:3). I can prevent seeing beyond the bounds when the cam displays less than the layout's height, but not if the cam displays the complete layout's width.

    In short: If you use my solution and set the display to an aspect ratio of 1.5 (e.g. 720x480), you will indeed never see anything outside the layout's boundaries.

    (2)

    To get this working you need to take care of the horizontal and vertical aspects, but this needs to be splitted. That's why you will find so many globals like "lenPlayerW", "lenPlayerH", "zoomW", "zoomH", "lenCamW", "lenCamH" etc. This could be solved much more elegantly by using functions, but I was a bit too lazy

    Basically, the expressions calculate a horizontal zoom and a vertical zoom and apply the one with the lowest value to the camera.

    The position of the cam is set manually to be able to clamp the camera display to the layout's boundaries. This is very straight forward.

    Both the zoom and the position of the camera are set using the lerp versions "Smooth Zoom" and "Move To Position". This is only in case you might want to have some lag in either of them. If so, just raise the milliseconds value of them both to your needs.

    A cooperative game with one display? I'm curious about it. That could be very interesting. Hope to see some screens soon

    EDIT: Forgot to say that you don't need the AdvancedCamera object for this solution. You might as well just use "System: Set zoom" and "System: Set scroll to x" resp. "System: Set scroll to y"

  • Thanks a lot for the help!

    I'm not very familiar with the Function object... so I tried my best to replace all of the global variables (except the 'lenPlayerArea' variable) with Function objects. Here is my result. Please scrutinize and correct me.

    Also, it's not really going to be co-op, I don't think. (My friend is the main designer.) The player will control both characters, but the controls will be mirrored for the character on the opposite side of the map.

    Sorry to get your hopes up.

    I'll try to get screenshots up as soon as I create some assets!

  • I'm not very familiar with the Function object... so I tried my best to replace all of the global variables (except the 'lenPlayerArea' variable) with Function objects. Here is my result. Please scrutinize and correct me.

    The function object is designed to hold more than one function call. You don't need more than one function object. I'll go over it, just give me a day or two. I'm currently thinking of extending it for you to have more control and flexibility. But no promises

    Also, it's not really going to be co-op, I don't think. (My friend is the main designer.) The player will control both characters, but the controls will be mirrored for the character on the opposite side of the map.

    Wow, that sounds even more interesting. Could serve for mind-breaking puzzles

  • > I'm not very familiar with the Function object... so I tried my best to replace all of the global variables (except the 'lenPlayerArea' variable) with Function objects. Here is my result. Please scrutinize and correct me.

    >

    The function object is designed to hold more than one function call. You don't need more than one function object. I'll go over it, just give me a day or two. I'm currently thinking of extending it for you to have more control and flexibility. But no promises

  • The engine is ready for you to start that amazing mirrored movement game. I expect no less than a screenshot as soon as it is worth taking one

    I extended it a lot. Auto Zoom Engine should be flexible enough to go with the design ideas of you and your friend. Ever thought about a level, where not only one sprite mirrors the movement of the other, but one sprite only mirroring horizontal and one sprite only vertical movement of a third sprite? Well, if so, AZE will be with you

    Try the demo and start doing your own cameras. Good luck and much fun

    Just follow this link for downloading

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The engine is ready for you to start that amazing mirrored movement game. I expect no less than a screenshot as soon as it is worth taking one

    I extended it a lot. Auto Zoom Engine should be flexible enough to go with the design ideas of you and your friend. Ever thought about a level, where not only one sprite mirrors the movement of the other, but one sprite only mirroring horizontal and one sprite only vertical movement of a third sprite? Well, if so, AZE will be with you

    Try the demo and start doing your own cameras. Good luck and much fun

    Just follow this link for downloading

    mazing... simply astonishing. I sincerely GREATLY appreciate this! My friend is going to be ecstatic, too.

    I'll reply once I "get" it!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)