New better Floating-Origin (Than my previous)

I’ve finished a smaller Floating-Origin that will prevent bugs like an object being jittery from being so far away from the World object (What I previously used).
Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FloatingOrigin : MonoBehaviour
{
    public GameObject Player;
    private GameObject[] FloatingObjects;
    public string Tag = "Floating";

    // FixedUpdate is called twice per frame
    void FixedUpdate()
    {
        // Get objects with tag
        FloatingObjects = GameObject.FindGameObjectsWithTag(Tag);

        // X
        if (Player.transform.position.x > 10)
        {
            Player.transform.position += new Vector3(-10, 0, 0);
            foreach (GameObject selected in FloatingObjects)
                selected.transform.position += new Vector3(-10, 0, 0);
        }
        else if (Player.transform.position.x < -10)
        {
            Player.transform.position += new Vector3(10, 0, 0);
            foreach (GameObject selected in FloatingObjects)
                selected.transform.position += new Vector3(10, 0, 0);
        }


        // Y
        if (Player.transform.position.y > 10)
        {
            Player.transform.position += new Vector3(0, -10, 0);
            foreach (GameObject selected in FloatingObjects)
                selected.transform.position += new Vector3(0, -10, 0);
        }
        else if (Player.transform.position.y < -10)
        {
            Player.transform.position += new Vector3(0, 10, 0);
            foreach (GameObject selected in FloatingObjects)
                selected.transform.position += new Vector3(0, 10, 0);
        }


        // Z
        if (Player.transform.position.z > 10)
        {
            Player.transform.position += new Vector3(0, 0, -10);
            foreach (GameObject selected in FloatingObjects)
                selected.transform.position += new Vector3(0, 0, -10);
        }
        else if (Player.transform.position.z < -10)
        {
            Player.transform.position += new Vector3(0, 0, 10);
            foreach (GameObject selected in FloatingObjects)
                selected.transform.position += new Vector3(0, 0, 10);
        }
    }
}

I get that it’s not the most human-readable, but it works.
Feedback of any bugs is appreciated.

1 Like

Though you can’t move too fast because it won’t be able to keep up.

Thanks for sharing. I think it’s a lot weta than your previous one.