Hello, Im creating a 2D platform game and yes, it has two different character, one on the left and other on the far right side of the game. I’d made the camera to follow the character by doing it as a child of the character, but that will only make it follow the first character as I drag the character as target of camera. I use space button for character switchings. And the camera should follow the current character. Thanks and have a nice day.
I haven’t tried this, so there is my disclaimer. I would try to have an equation that decides the distance, and locations of the characters (assuming they move independently of each other, left and right/up and down) so that you can decide how “zoomed” to make the camera, keeping a safe area around the edges so the players can see incoming enemies or obstacles. So basically you would take the distance, and perhaps an additional five units of space extra for that safe area, and then do a comparison of those locations to the edges of the screen, and if the screen doesn’t see far enough away, or close enough to each character, zoom out, and then ofcourse you need to take the middle position of the two characters and center the camera there to keep them inside the view of the camera.
I won’t write this kind of script for free, and I doubt you will find someone to do it for you for free. But with enough time and trial and error I bet someone could write this script, even with a novice level of experience. It’s not a super easy one though, good luck!
You can give a camera to each one and only enable one at a time.
That was my thought when I read the OP @Fraconte .
@RalphSpoon , is there any reason you can’t use two cameras?
Also, if it doesn’t need to be an immediate switch, you could also used the supplied Smooth Follow and add a controller script to change the target value. Would be like the camera quickly turns and eases onto the other target. Could be interesting.
I guess I may have misunderstood, I thought the OP needed one camera to follow two characters, moving independently at the same time. But if you need to only follow one character, and switch between the two characters when using them at different times, then just switching the target of the camera, or switching between two cameras should work just fine!
I personally also like this way more than instant switch…
thanks @crag . im new to unity didnt that its possible to have 2 camera or more. thanks.
Ah, cameras are vital. Play with them lots! You could use 2 cameras at once and have a “picture in picture” (aka PIP) and toggle between them. If you can’t find example code to try, drop a line, I’m sure I have some.