Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by geekedatbirth · Sep 10, 2011 at 06:57 PM · cameracontrollerswitchswap

Swapping Cameras Disables Keyboard Input

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.

 moveCamera.camera.active = true;
 battleCamera.camera.active = false;
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image asafsitner · Sep 10, 2011 at 07:14 PM 0
Share

Did you add the camera controller script to the third-person camera as well? Also, yea, as Charles said, save yourself the trouble and just change the camera position and control mode.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by geekedatbirth · Sep 10, 2011 at 08:39 PM

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.

 Input.ResetInputAxes();`

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Charles-Van-Norman · Sep 10, 2011 at 07:11 PM

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:

      Debug.Log("Keystroke "+Event.current.character+" recorded at time "+Time.time+" from [insert your script name here]");



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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by geekedatbirth · Sep 10, 2011 at 07:55 PM

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 :

 var worker : GameObject = GameObject.Find("construction_worker");
     randAttack = 0;
     battleCamera.transform.position = moveCamera.transform.position;
     battleCamera.transform.rotation = player1.transform.rotation;
     moveCamera.camera.enabled = false;
     battleCamera.camera.active = true;
     battleCamera.camera.enabled = true;
     player1.gameObject.GetComponent(ThirdPersonController).isControllable = false;
     var enemy1  = Instantiate(enemy1, player1.transform.TransformPoint(Vector3.forward * 12), Quaternion.identity);
     enemy1.transform.LookAt(player1.transform);
     var enemy2  = Instantiate(enemy2, enemy1.transform.TransformPoint(Vector3.left * distBetweenMobs), Quaternion.identity);
     enemy2.transform.LookAt(player1.transform);
     var enemy3  = Instantiate(enemy3, enemy1.transform.TransformPoint(Vector3.right * distBetweenMobs), Quaternion.identity);
     enemy3.transform.LookAt(player1.transform);

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

setting a character controller orientation by script 1 Answer

Switch Camera on Input in C# 3 Answers

Singling out mutiple Character movement 3 Answers

Gamepad Camera + Interference from Mouse 1 Answer

how to swap a mesh using an array 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges