I'm trying to make a fighting video game in which you can play two players on the same device.
I already have the movement of each player but I need to make a camera that follows the two players without anyone leaving the screen, It's something like Street Fighter.
I'm sorry for bad English;)
To scroll in the middle of two players use lerp(player1.x, player2.x, 0.5)
If you need to zoom out when players are far away from each other, you can set layout scale to something like this:
min(1, (ViewportRight("HUD")-ViewportLeft("HUD")) / (abs(Player1.X - Player2.X)*1.1))
Where "HUD" is a layer with Scale Rate=0.
dop2000 Thank you, it worked correctly, but is there any way to make the characters not leave the screen?
Yes, but you need to explain what you want, maybe post your project file or some screenshots.
dop2000 I have almost nothing in my project but if you need it here it is: dropbox.com/s/4pxgljl29zqvow7/FightingGame.capx
Well it's something like this what I need: construct.net/en/free-online-games/rec-jp-fight-3779/play
In that game you can't move back further than screen width.
So you can keep zoom at 1 and restrict player movement instead. For example for player #2 if "Right" key is pressed and the distance between players is less than some number, simulate moving to the right. If the distance is greater than that number, the player will not move.
Formula for distance: abs(Player1.x-Player2.x)
Thanks, it worked, but not exactly as I needed it, it would be great if you could send me a capture or a capx because I don't speak much English and I don't understand well, I did what you said but the characters still come out of the screen.
Or, better yet, post your capx with the things you tried, and I'll tell you what to change.
Well here is the capx of what I did: dropbox.com/s/j0s654dsjgo8nsj/FightingGame1.capx
by the way I don't think that camera movement is adequate.
I see you didn't try restricting player movement as I suggested..
Develop games in your browser. Powerful, performant & highly capable.
oh it works very well but when the characters reach the center of the layout player1 cannot move until player2 moves first, is there any way that this does not happen?
That's how it's done in that Rec Jp Fight game you posted. You can change conditions like this for both players, then they will be able to move past each other.
Thank you very much man ;)