- Home /
Exclude Objects From FloatingOrigin
Hello i am using a script i found on the wiki which resets my origin back to 0,0,0 and shifts 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 this 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;
}
}
}
}
}
}
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.
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.
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 things 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 things 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.
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.
Can't believe I posted some code I hadn't checked and it worked!