- Home /
Camera Problem: following variable Player(s)
Hi
I'am working on a classic 2D Platforms game, with Unity, and C# scripts.
The "original" feature: there are 2 (or 3 depending on the levels) characters to control (player1, player2, player3)
ONLY ONE is active at a time, and a UI.button switch from one to another.
To be complete, I also have 2 zoom button on this camera (in/out).
It works well for the player's movements (and zoom), but I can't control the camera, or more accurately, to chose which character to follow...
The camera stay attached to "player1".
In my "ideal" idea :
player1 active, camera following this player1
click on button
camera move (at variable speed) to player2
camera attach to player2
player2 become active
camera follow now player2
So, only one camera... (i think)
It may be simple, but being relatively new to UNITY, I have never encountered this kind of problem (and my Internet searches did not yield anything)
Thank's in advance if you have a solution to change the player followed by a camera...
Answer by ViktorKurtev · Feb 18, 2018 at 10:30 AM
A good idea could be to create a dedicated camera target object, that you can move between the different player positions. For example create an empty game object, attach it as a child object to Player 1. Make your camera follow that empty game object and whenever you press the key for switching between players, you could for example move the empty game object linearly between the 2 positions. When the empty game object arrives at the player 2 position, make it a child object of Player 2 instead. That way you wouldn't have to worry about moving the target manually, since it will follow your player regardless of what happens. Hopefully you find this helpful =)
Answer by tata_unlimited · Feb 18, 2018 at 10:45 AM
You can also use a simple camera follow script: https://unity3d.com/learn/tutorials/projects/2d-ufo-tutorial/following-player-camera and then just switch the camera target to your second player transform whenever you want using a simple line of code.
Answer by RichnouRichnou · Feb 18, 2018 at 07:15 PM
Thanks for ideas...
I'll try as soon as possible :-)
Your answer
Follow this Question
Related Questions
camera that follow the player ? 1 Answer
Make camera follow player and align direction 0 Answers
Camera points towards object but doesn't go to it 2 Answers
Sniper Scope clipping with a gameobject 0 Answers