Create a camera that is always set between 2 objects

Get help using Construct 2

Post » Thu Jan 21, 2016 2:20 am

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.
B
7
S
2
G
1
Posts: 38
Reputation: 917

Post » Thu Jan 21, 2016 3:15 am

The camera position is a simple average of the two object's positions, so the X position of your camera should be...

Code: Select all
(player1.X + player2.X) / 2

Zoom would be something along the lines of...

Code: Select all
if player1.X < player2.X
    set layout scale to WindowWidth / (player2.BBoxRight - player1.BBoxLeft)
else
    set layout scale to WindowWidth / (player1.BBoxRight - player1.BBoxLeft)

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.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » Fri Jan 22, 2016 12:48 am

Oh, interesting solution. Thanks for sharing it. I will try it.
B
7
S
2
G
1
Posts: 38
Reputation: 917


Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, NECRONOMICRON, plinkie and 23 guests