I'm trying to swap from one third person camera (attached to the player and the controller) to a third person camera that pans to the right and out when prompted.. everything is working fine except it seems when I swap from the first camera to the separate camera all keyboard and button input is no longer recognized... as if the Third Person Controller gets disabled when I turn off the main camera. Any help with this would be appreciated.. hopefully I explained it well enough.
My apologies for wasting anyone's time but I finally discovered the issue. This line was included in the 3rd person script provided by Unity... after researching what this call does, everything made complete sense.
If nothing else, maybe another beginner will someday come across this same issue and this unfamiliar line in the character controllers and find this solution. Seems so obvious now, but that Controller script is a bit intimidating when you look at it through the eyes of a newbie like myself.
Can you supply more information about the structure of your code? Activating or deactivating a camera should not affect controllers or anything else, unless those controllers are dependent on the camera being active (for example, using camera.screenPointToRay to determine where the controller should move, which is not uncommon.) If you're tying the controller to the camera, you will need to dynamically change which camera the controller is tied to when swapping the camera.
Have you tried adding a Debug log to confirm the controller scripts are running? Try adding this into your controller script:
Another "workaround" style solution: DONT SWITCH CAMERAS! Instead, simply change the transform.localPosition and transform.rotation of your camera between the FPS and 3rd person locations.
answered Sep 10 '11 at 07:11 PM
Charles Van Norman
I've considered the final solution you gave me and just using the same camera, but I want several cameras that show specific layers for effect, and this seemed easier but apparently I was wrong about that since I can no longer control my character when I swap cameras.
As far as setup, I used the built in 3rd person controller and selected the 'Main Camera' as the one to follow the player... position in relation to the 'player1' game object (the main character) is done via code. When a battle sequence starts, I cut to a second camera which hides certain layers and then pans to the side and enemies are displayed on the opposite side of the screen. This all seems to work perfectly.
I have tested the 'input' key using a print statement and it works up until I swap the cameras. Here is the code for swapping cameras :
the code above just sets the 'battlecam' to the same position and rotation as the main camera so it is a seamless transition (minus the fact that layers are hidden) and then pans to side and out in front of the player character. the player stops, and on the opposite side of the screen (now being viewed from the side rather than behind the player) the enemies are loaded.
What the problem is, the player can jump, move, etc. before the random battle occurs. Once I swap cameras, all input from the keyboard is no longer being recorded, regardless of whether it is in the character controller or attached to the battle camera. I feel like I'm just missing something simple that would allow keyboard input for when swapping to the battle camera but I cannot find a solution for the life of me.
Currently the only script attached to the battle camera is the one to script it's movement.
I'm sure my code is very amateur, but for now it works. I've been coding in other languages for a very long time but am pretty new to Unity, but this is how I learn. Tutorials help me up to a point, but I have to jump in, break things, try new things, etc. in order for me to figure out why things work a certain way... which is what I'm attempting to do now, but I cannot figure out why I can't use keys when I swap cameras... it seems so counter-intuitive to me.
PS. The 'enabled' and 'active' things are from attempts to figure this out. My original code ONLY set the maincam.active to false and the battlecam.active to true.