Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 FuzzyLuke · Dec 06, 2012 at 10:02 AM · freezinglocked

Character freezes when I change camera

Hello.

Yesterday I was trying to figure out how to play with cameras ingame.

The idea was to make it so the camera switches whilst playing like in Resident Evil games, when the character steps into an area, the camera will switch to either a more dramatic view or just a more comfortable view of the area, say for when the character goes behind a wall or into a different section of the room.

The problem I was having is that I want 2 types of cameras, one that follows the character (in third view), and another type that will be static.

My main camera follows the character in an isometric view, so the player can't rotate the camera, so, when they go behind a wall or object, I want the camera to switch, and when they step out of that area I want it to go back to the isometric view. I hope its not confusing to understand.

So, I followed some tutorials and my isometric camera is working perfectly. Then I made a test to switch cameras. So now I have 2 cameras in my Project view, "CharacterCamera" is the camera that's following the character, and "StaticCamera" is the one that is locked into position looking at a certain area of the field.

I then made a script that I attached to both cameras, what it does is, upon pressing the keyboard key "E", the "CharacterCamera" is disabled and the "StaticCamera" is enabled, using a script I found on this website:

 GameObject.Find("CharacterCamera").GetComponent("Camera").active = false;
 GameObject.Find("StaticCamera").GetComponent("Camera").active = true;

So, it all works out, however there's a problem, my camera does change, however my character stops moving and I get a error on the Console Log, I didn't write the error down, but it had something to do with the ThirdPersonController.Update() and what not, the idea I got was that now the game does not know how to follow the character and it gives an error making the game crash, I couldn't move at all, but the character was now in the "StaticCamera" view as I wanted it to.

I know I should post the error but I forgot to note it down and I'm at work at the moment so can't provide it at the moment, but this is all I did, hopefully someone has run into this issue and can help?

Update:

This is the error I'm getting upon changing cameras:

 NullReferenceException ThirdPersonController.UpdateSmoothedMovementDirection () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js:130) ThirdPersonController.Update () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js:304)
Comment
Add comment
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

3 Replies

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

Answer by uvavoo · Dec 06, 2012 at 03:24 PM

I think the error is deactivating the main camera. Set up a trigger where when the player enters it the camera switches and when the player leaves it switches back to the main camera. It is important to set the temporary cameras 'depth' to a higher number than 0. This will put the new cameras view above the main cameras, the character and main camera should continue to function as normal.(see screenshot)alt text

Use something like the following code. using UnityEngine; using System.Collections;

 public class SwitchCam : MonoBehaviour
     
 {
     void  OnTriggerEnter ( Collider other  )
     {
         if (other.gameObject.tag == "Player")
         
         {
             {
                 GameObject Tcam6 = GameObject.Find("temp_Camera6");
                     Tcam6.camera.enabled = true;
              }
         }
     }
     
     void OnTriggerExit ( Collider other  )
     
     {
         if (other.gameObject.tag == "Player")
         
         {
             {
                 GameObject Tcam6 = GameObject.Find("temp_Camera6");
                     Tcam6.camera.enabled = false;
              }
         }
     }
 
 }

screen shot 2012-12-06 at 11.06.18.jpg (25.0 kB)
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 FuzzyLuke · Dec 06, 2012 at 08:19 PM

Thank you for the help, that did the trick.

And even bigger thanks for explaining triggers to me! :)

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 uvavoo · Dec 07, 2012 at 09:47 AM

You're welcome, glad its working for you.

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity plugin locked files 1 Answer

Multiple coroutines starting from Update() freeze/crash Unity 0 Answers

Why does unity freeze when i click play? It also happens in an empty project 0 Answers

Navmesh Pathfinding Freeze (may be a while loop thing) 0 Answers

Fatal Error Database is Locked 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