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 shaken · Apr 12, 2013 at 10:21 PM · camerafreezelocklocked

Camera freezes while moving, game is not locked up.

I'm debugging an activity where our camera will move to a location / rotation, the user will perform a small task, and then the camera moves to the next location / rotation, and this cycle repeats until the activity is complete. Also, this activity is loaded as a prefab, meaning when the user engages the activity, we place a prefab somewhere in the world, and move the camera to that location and let the prefab "take control" by disabling the player while it is active.

The issue is that the main camera will freeze right when we activate this activity prefab. The GUI camera and game logic are still working, as we can still interact with gui elements, and we can see in scripts that the game logic is still going. In order to get the camera to unfreeze, I have to make Unity lose focus (alt-tab or click on another window) and then come back to it. The camera will then start rendering the activity like normal. However, the issue occurs again during the activity, while the camera is moving to a new location.

Now, I have successfully stopped this from happening by pulling in the far plane for the main camera to a very small number (10), but this prevents the scenery around the activity from being rendered and well... it just looks bad. That leads me to suspect that it has something to do with culling, but really I'm at a loss here.

Has anyone seen this occur? Does anyone know a way to prevent it from happening?

Thanks for your time.

EDIT: Here is the script controlling the camera for the prefab. I did not write it.

 using UnityEngine;
 using System.Collections; 
 
 public class RoofCam : MonoBehaviour {
     
     private RoofNode cameraNode;
     
     public float slerpTime = 1f;
     public float backDistance = 4.5f;
     
     public RoofNode CameraNode {
         get { return cameraNode;}
         set {  
             
             setNode(value);
         }
     }
     // Use this for initialization
     void Start () {
          basePosition = Camera.mainCamera.transform.position;
          baseOrientation = Camera.mainCamera.transform.rotation;
          toPosition = basePosition;
          toOrientation = baseOrientation;
     }
     
     // Update is called once per frame
     //private float currentTime = 0;
     
     void Update () {
     
         //Sway();
         
         //setNode(cameraNode);
         if(basePosition != toPosition){
             currentTime += Time.deltaTime;
             
             if(currentTime <= slerpTime){
                 float slerpStep = currentTime/slerpTime;
                 
                 Vector3 newPos = Vector3.Slerp(basePosition, toPosition, slerpStep );
                 Quaternion newOri = Quaternion.Lerp(baseOrientation, toOrientation, slerpStep);
                 
                 Camera.mainCamera.transform.position = newPos;
                 Camera.mainCamera.transform.rotation = newOri;
         
             }
             else{
                 basePosition = toPosition;
                 baseOrientation = toOrientation;
                 currentTime = 0;
             }
         }
 
     }
     
     
     Vector3 swayToPos;
     Vector3 swayToExtents = new Vector3(1, 1, 1);
     Quaternion swayToOri;
     float swayTime = 1.0f;
     float currentTime = 0f;
     float restTime = .5f;
     bool toBasePosition = false;
     bool isResting = true;
     void Sway()
     {
         //periodically set swayToPos
         //bound to extents
         currentTime += Time.deltaTime;
         
         if(currentTime >= swayTime)
         {
             //flip
             if(!toBasePosition){
                 swayToPos = new Vector3(Random.Range(-swayToExtents.x + basePosition.x, swayToExtents.x+basePosition.x), 
                                         Random.Range(-swayToExtents.y + basePosition.y, swayToExtents.y + basePosition.y), 
                                         Random.Range(-swayToExtents.z + basePosition.z, swayToExtents.z + basePosition.z));
             }
             else{
                 swayToPos = basePosition;
             }
             
             currentTime = 0f;
             isResting = true;
         }
         
         if(isResting){
             if(currentTime > restTime){
                 currentTime = 0;
                 isResting = false;
             }
         }
         
         Vector3 newPos = Vector3.Lerp(transform.position, swayToPos, currentTime/swayTime);
         transform.position = newPos;
     }
     
     Vector3 basePosition ;
     Quaternion baseOrientation ;
     Vector3 toPosition ;
     Quaternion toOrientation ;
     void setNode(RoofNode node)
     {
         if(node == null)
             return;
         if(cameraNode == null)
         {
             basePosition = node.Position;
             baseOrientation = node.Rotation;
             Camera.mainCamera.transform.rotation = baseOrientation;
             Camera.mainCamera.transform.position = basePosition;
         }
         else if( cameraNode != node)
         {
             currentTime = 0;
             baseOrientation = Camera.mainCamera.transform.rotation;
             basePosition = Camera.mainCamera.transform.position;
         }
             
         cameraNode = node;
         
         this.toOrientation = node.Rotation;
         
         this.toPosition = node.Position + ( node.Forward * -backDistance);
     }
 }
 
Comment
Add comment · Show 2
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 aldonaletto · Apr 12, 2013 at 10:28 PM 0
Share

You should post the prefab script - apparently it's the responsible for freezing the camera.

avatar image shaken · Apr 12, 2013 at 10:35 PM 0
Share

Good suggestion aldonaletto, updated question with the script that controls the camera for the prefab.

0 Replies

· Add your reply
  • Sort: 

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

11 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 avatar image

Related Questions

How to Freeze move camera 3 Answers

Freeze an Axis Rotation Help? 0 Answers

Unity window is freezed when after pressing 'Attack to unity' button in Visual studio.,Unity window is freezed when pressing 'Attach to Unity', so I am not able to debug... 0 Answers

Camera Change Bug 0 Answers

Is it bad to add a mouse Lock at MouseLook Script? 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