Create a camera that is always set between 2 objects

0 favourites
  • 3 posts
From the Asset Store
This Girls Game allows young fashionistas to develop their taste and skills as a fashion designer.
  • Hi guys, so i was wondering... How could I create a camera that is always between two instances/players/objects? We can see something similar in new super mario bros series (more specifically in new super mario bros wii U), in which, I believe, the camera is set between the player closest to the right limits and the one closest to the left limits of the screen. I tried to do:

    Every tick > Set Camera_Position(global var) to (expression)distance(Player2.X,Player2.Y,Player1.X,Player1.Y) - This would give me the distance between the X and Y of the 2 instances. Then I did:

    Camera(object with scroll to behavior) set X > Camera_Position(global var)/2

    But it didn't work. Anyway, I had no clue on how to solve this and how could I do the zoom out limit based on the distance between them. Do you guys have any thoughts about it?

    Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The camera position is a simple average of the two object's positions, so the X position of your camera should be...

    (player1.X + player2.X) / 2[/code:3jpn49ek]
    Zoom would be something along the lines of...
    
    [code:3jpn49ek]if player1.X < player2.X
        set layout scale to WindowWidth / (player2.BBoxRight - player1.BBoxLeft) 
    else 
        set layout scale to WindowWidth / (player1.BBoxRight - player1.BBoxLeft)
    [/code:3jpn49ek]
    Note that extending the camera positioning to work both horizontally and vertically is straightforward, but doing so for zoom would involve dealing with some extra edge cases.
  • Oh, interesting solution. Thanks for sharing it. I will try it.

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