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
6
Question by Suyuanhan · Jul 12, 2011 at 01:38 AM · camerascenecontrol

Can scene camera follow the object?

There is a GameOjbect(walker) in My scene,and it move fast when in play mode, And I have to adjust other GameOjects' position around the walker, Can I use a script or something else to control the scene's camera (note:not the camera in play mode).

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 DaveA · Jul 12, 2011 at 04:40 AM 0
Share

Can you explain that further? You say 'move fast when in play mode' but then 'not the camera in play mode'. Are you talking about the editor's camera(s)?

7 Replies

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

Answer by Joshua · Jul 12, 2011 at 04:50 AM

[EDIT: as of Unity 4.3, press Shift-F to lock the scene view to the selected object]

To control the SceneView's camera, you have to use some undocumented (and therefore: officially not supported) methods.

SceneView.lastActiveSceneView.camera.pivot allows you to directly alter the pivot point of the sceneView camera. Using some other standard camera functions this should allow you to do what you want.

Scripts using this need to be in an Editor folder.

If you really want to do this I suggest you decompile UnityEditor.dll and have a look in the SceneView and the Camera classes.

Comment
Add comment · Show 1 · 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 Suyuanhan · Jul 14, 2011 at 01:07 AM 0
Share

Thanks,that helps me a lot.

avatar image
3

Answer by Lttldude · Oct 21, 2012 at 05:27 AM

I just wrote a script that allows multiple SceneViews to follow a gameobject in edit and play mode. I uploaded it to the Unity3d Wiki: http://wiki.unity3d.com/index.php/SceneViewCameraFollower Check it out.

Comment
Add comment · Show 1 · 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 petey · Feb 10, 2017 at 01:42 AM 0
Share

This is ace! Thanks mate :) Saving me so much time here!

avatar image
3

Answer by yoyo · Apr 08, 2014 at 08:25 PM

I'm not certain when this feature was introduced, but as of Unity 4.3 you can press Shift-F (or double-tap F) to lock the scene camera to the selected object. When the object moves, the scene camera will follow it.

See hotkey documentation.

Comment
Add comment · Show 1 · 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 Luckymouse · Nov 22, 2018 at 02:25 PM 0
Share

"double-tap F " works!. The scene view camera follow the selected moving gameobject in the Play mode. By the way why this trick is undocumented. Thanks for the tips.

[Edit] In version Unity 2018.3 use "Shift" + "F" key to lock the camera to moving object. In the future version maybe unity will change back to double tap "F" again, but I'm not sure.

avatar image
-3

Answer by nbase · Jul 12, 2011 at 03:35 AM

There's a script named 'SmoothFollow' in the standard assets. Add it to the camera and drag the object you want it to follow into the 'Target' slot of the script

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 Code_Monkey_Refurbished · Sep 21, 2015 at 06:44 PM

 //Allows multiple SceneView cameras in the editor to be setup to follow gameobjects.
 //October 2012 - Joshua Berberick
  
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
  
 [ExecuteInEditMode]
 public class SceneViewCameraFollower : MonoBehaviour
 {
 #if UNITY_EDITOR
  
     public bool on = true;
     public bool onlyInPlayMode = false;
     public SceneViewFollower[] sceneViewFollowers;
     private ArrayList sceneViews;
  
     void LateUpdate()
     {
         if(sceneViewFollowers != null && sceneViews != null)
         {
             foreach(SceneViewFollower svf in sceneViewFollowers)
             {
                 if(svf.targetTransform == null) svf.targetTransform = transform;
                 svf.size = Mathf.Clamp(svf.size, .01f, float.PositiveInfinity);
                 svf.sceneViewIndex = Mathf.Clamp(svf.sceneViewIndex, 0, sceneViews.Count-1);
             }
         }
  
         if(Application.isPlaying)
             Follow();
     }
  
     public void OnDrawGizmos()
     {
         if(!Application.isPlaying)
             Follow();
     }
  
     void Follow()
     {
         sceneViews = UnityEditor.SceneView.sceneViews;
         if(sceneViewFollowers == null || !on || sceneViews.Count == 0) return;
  
         foreach(SceneViewFollower svf in sceneViewFollowers)
         {    
             if(!svf.enable) continue;
             UnityEditor.SceneView sceneView = (UnityEditor.SceneView) sceneViews[svf.sceneViewIndex];
             if(sceneView != null)
             {
                 if((Application.isPlaying && onlyInPlayMode) || !onlyInPlayMode)
                 {
                     sceneView.orthographic = svf.orthographic;
                     sceneView.LookAtDirect(svf.targetTransform.position + svf.positionOffset, (svf.enableFixedRotation) ? Quaternion.Euler(svf.fixedRotation) : svf.targetTransform.rotation, svf.size);    
                 }
             }
         }    
     }
  
     [System.Serializable]
     public class SceneViewFollower
     {
         public bool enable;
         public Vector3 positionOffset;
         public bool enableFixedRotation;
         public Vector3 fixedRotation;
         public Transform targetTransform;
         public float size;
         public bool orthographic;
         public int sceneViewIndex;
  
         SceneViewFollower()
         {
             enable = false;
             positionOffset = Vector3.zero;
             enableFixedRotation = false;
             fixedRotation = Vector3.zero;
             size = 5;
             orthographic = true;
             sceneViewIndex = 0;
         }
     }
  
 #endif
 }
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
  • 1
  • 2
  • ›

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

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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Can i load a scene with no Camera 1 Answer

(CLOSED) Plane Failing to Render When Camera is Switched Until Scene is Reloaded?! 0 Answers

How do i remove the gui windows in my scene 1 Answer

turn off selection in the Scene View 0 Answers


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