• 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 BritishGuy · Jan 21, 2015 at 01:35 AM · cameraresetfloatingoriginexclude

Exclude Objects From FloatingOrigin

Hello i am using a script i found on the wiki w$$anonymous$$ch resets my origin back to 0,0,0 and s$$anonymous$$fts all game objects with me, I have been trying to exclude some objects as i need them to be around the origin at all times, any way to add an exception to t$$anonymous$$s script for chosen objects? Thanks.

 // FloatingOrigin.cs
 // Written by Peter Stirling
 // 11 November 2010
 // Uploaded to Unify Community Wiki on 11 November 2010
 // URL: http://www.unifycommunity.com/wiki/index.php?title=Floating_Origin
 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(Camera))]
 public class FloatingOrigin : MonoBehaviour
 {
     public float threshold = 100.0f;
     public float physicsThreshold = 1000.0f; // Set to zero to disable
     public float defaultSleepVelocity = 0.14f;
     public float defaultAngularVelocity = 0.14f;
     
     void LateUpdate()
     {
         Vector3 cameraPosition = gameObject.transform.position;
         cameraPosition.y = 0f;
         if (cameraPosition.magnitude > threshold)
         {
             Object[] objects = FindObjectsOfType(typeof(Transform));
             foreach(Object o in objects)
             {
                 Transform t = (Transform)o;
                 if (t.parent == null)
                 {
                     t.position -= cameraPosition;
                 }
             }
             
             objects = FindObjectsOfType(typeof(ParticleEmitter));
             foreach (Object o in objects)
             {
                 ParticleEmitter pe = (ParticleEmitter)o;
                 Particle[] emitterParticles = pe.particles;
                 for(int i = 0; i < emitterParticles.Length; ++i)
                 {
                     emitterParticles[i].position -= cameraPosition;
                 }
                 pe.particles = emitterParticles;
             }
             
             if (physicsThreshold >= 0f)
             {
                 objects = FindObjectsOfType(typeof(Rigidbody));
                 foreach (Object o in objects)
                 {
                     Rigidbody r = (Rigidbody)o;
                     if (r.gameObject.transform.position.magnitude > physicsThreshold)
                     {
                         r.sleepAngularVelocity = float.MaxValue;
                         r.sleepVelocity = float.MaxValue;
                     }
                     else
                     {
                         r.sleepAngularVelocity = defaultSleepVelocity;
                         r.sleepVelocity = defaultAngularVelocity;
                     }
                 }
             }
         }
     }
 }
Comment
Add comment · Show 3
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 BritishGuy · Jan 21, 2015 at 12:19 PM 0
Share

Anyone? The smallest bit of info can go a long way.

avatar image BritishGuy · Jan 21, 2015 at 01:22 PM 0
Share

It has been a while since i have done any coding at all but the way i see it is this script is finding all transforms, rigidity and particles and adding them to a Objects[] list, But how would i exclude certain objects with a specific TAG so this script does not effect them?

I could be wrong and i am probably complicating things so if anyone could point me in the right direction it would be greatly appreciated as i am currently going bold on my head over this thing. Thanks.

avatar image BritishGuy · Jan 21, 2015 at 03:42 PM 0
Share

After 14 hours of Google searching i have noticed other people with the same problem as me without any solutions and they are 1 - 3 year old posts.

The main problem but not the only problem is the Gui, it gets pushed back from the origin in turn making my Hud Gui vanish, It also breaks the asset Waypoint Hud.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Mmmpies · Jan 21, 2015 at 04:02 PM

Should be a way of doing it, how many objects are you wanting to move?

Where it does the foreach you can do t$$anonymous$$ngs like check the name of the object or the tag.

 if(t.tag  == "NoMove")
 {
     Debug.Log("Not moving " + t.name);
 }
 else
 {
     if (t.parent == null)
     {
         t.position -= cameraPosition;
     }
 }

not tested that code but give it a shot, course you gotta tag the t$$anonymous$$ngs you don't want to move NoMove, or whatever works for you. Same for the rigidbody stuff, reference it and if you don't want it moving then just skip it.

Comment
Add comment · Show 2 · 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 BritishGuy · Jan 21, 2015 at 04:48 PM 0
Share

I can not believe it was that simple, It is this lack of sleep lol.

Thanks allot for taking the time to help me out, Works wonders thanks.

avatar image Mmmpies · Jan 21, 2015 at 05:50 PM 1
Share

Can't believe I posted some code I hadn't checked and it worked!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

26 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 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 reset GameObject to original scale 2 Answers

3drd person camera reset 0 Answers

Orbit around player, but allow re-centering of camera via button press? 2 Answers

Mouse Orbit Reset Camera 0 Answers

3rd person camera to player 2 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