Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Floating Origin - Moving Smaller Scale system relative to parent

Discussion in 'Scripting' started by Cyrussphere, Aug 24, 2018.

  1. Cyrussphere

    Cyrussphere

    Joined:
    Jul 1, 2016
    Posts:
    129
    Hi All,

    I've been playing around with floating origin for a space sim game and got it down to where I like it but I am now having issues with another part of it that I would like to add in. Currently my SolarSystem scale is 1,000,000 meters per 1 Unity unit. I have a smaller copy of this same SolarSystem at a scale of 10,000,000 meters per 1 Unity unit. What I would like to do is while i am moving my SystemLevelContainer (the larger scale parent) around the player (player stays at Vector 0), I would like to also move the smaller scale container along with the larger one but on its own scale. Below is my current floating origin script I am using;

    Code (CSharp):
    1. void FloatingOrigin()
    2.     {    
    3.         float distanceFromOrigin = Vector3.Distance(transform.position, Vector3.zero);
    4.         //player movement direction
    5.         Vector3 direction = transform.position - Vector3.zero;
    6.  
    7.         if(distanceFromOrigin >= safeArea)
    8.         {
    9.             //Set player back to 0
    10.             transform.position = Vector3.zero;
    11.             //Move universe parent around player in proper direction
    12.             SystemLevelContainer.transform.position += direction * -1;
    13.         }
    14.     }
    Edit: I tried something along the lines of;
    SmallScaleLevelContainer.transform.position += SystemLevelContainer.transform.position * 0.1f which almost worked except when I tried to move in another direction, the small scale kept going forward..also it was really choppy
     
    Last edited: Aug 24, 2018
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Code (csharp):
    1.  
    2. smallerScale.transform.position = biggerScale.transform.position * scaleRatio;
    3.  
     
  3. Cyrussphere

    Cyrussphere

    Joined:
    Jul 1, 2016
    Posts:
    129
    Thanks for the quick reply. realized I forgot that part and was editing the main post right when you responded;

    I tried something along the lines of;
    SmallScaleLevelContainer.transform.position += SystemLevelContainer.transform.position * 0.1f which almost worked except when I tried to move in another direction, the small scale kept going forward..also it was really choppy
     
  4. Cyrussphere

    Cyrussphere

    Joined:
    Jul 1, 2016
    Posts:
    129
    Guess I had a brain fart, I missed some other things that were giving some issues..got this implemented and its working wonders..thanks for the help!