1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

How to get the in-game time/rotation of the sun?

Discussion in 'Programming (In-game)' started by c0d3n4m3, Jan 30, 2016.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. c0d3n4m3

    c0d3n4m3 Trainee Engineer

    Messages:
    16
    Hi all,

    I'm trying to write a script that will turn my station lights on during the night and off during the day. Is there a class or a method that I can access to know when the sun is up and the sun is down?

    In fact, is there a class that I can find out the rotation of the sun in regards to the planet?

    Sorry for the nubbie question, I'm just not 100% sure what to look for.


    Thanks all!
     
  2. gothosan

    gothosan Junior Engineer

    Messages:
    723
    As far as I know its currently impossible, there are however scripts that do something similar.. You could use solar panels for this and have a condition where if all solar panels output is zero then it must be night so turn on the lights
     
    • Agree Agree x 1
  3. c0d3n4m3

    c0d3n4m3 Trainee Engineer

    Messages:
    16
    Ah, great idea! Thank you, I shall implement this right away. :tu:
     
  4. Jaken Veina

    Jaken Veina Apprentice Engineer

    Messages:
    134
    Check out the Extra Programming Info mod, which provides altitude and velocity info's not normally available in ingame scripts. It should be possible, if Stan feels like it, to add a property for time-of-day or something along those lines.
     
  5. Tylus

    Tylus Apprentice Engineer

    Messages:
    427
    The idea with the solar panel output is quite good. If you know whats the maximum output of the solar panel, you can figure out easily if its moring, noon, evening or night.

    But still there is one risk. At the moment in space engineers the detailed info of some blocks is not updating correctly, so it may happen, that your program is provided with old data from the solar panels.

    So you need to check if you can do that right now.
     
  6. c0d3n4m3

    c0d3n4m3 Trainee Engineer

    Messages:
    16
    Yep, this is the case sadly. I have it all working, but the detailed info doesn't update sometimes/correctly, and so the script then fails to work.
     
    • Agree Agree x 1
  7. Tylus

    Tylus Apprentice Engineer

    Messages:
    427
    I hope this gets fixed soon.

    My scripts based on the solar panels output are also not working as intended anymore. I had one script which rotates my space station the same way as the sun does. basically it searched the point of highest solar output every 5 minutes (depending on duration of day). so it slowly rotates with the sun.

    But since the updates are not working, the skript always finds the same wrong, or a completely different location as "perfect". Well it still has enough power to survive and let me spawn there, but in the end its just not good enough anymore.
     
  8. Dakroth

    Dakroth Apprentice Engineer

    Messages:
    144
    I found a script that can determine "time of day" and do some extra stuff with it, but it all comes down to just setting a timer, really. Determine the solar cycle time, set zero to high noon or whatever, activate. Not super helpful, but that's how I've been able to do it.

    -Dakroth
     
  9. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    Get your day length from the world setup.
    Place a rotor in world
    Convert day length to minutes.
    Divide 1 by minutes.
    Set rotor velocity to the result (ctrl+left click).
    The rotor will now do one complete revolution per day.
    Wait till noon, turn rotor on.
    Sample rotor angle using
    Code:
    float Angle = MathHelper.ToDegrees(ThisRotor.Angle);
    Then run the angle through some more math and a short if chain to get hours, minutes and seconds.
    If you have a long day length you can double or quadrouple the rotor speed and maintain a counter on an lcd to remember which revolution you are on.
     
    • Like Like x 1
    • Informative Informative x 1
  10. c0d3n4m3

    c0d3n4m3 Trainee Engineer

    Messages:
    16

    Very nice, thank you!
     
  11. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    For best result you can orient axis so, that it points to -Y pole of world. Take your current GPS, than make Y coordinate -10 000 000. So you will get a point to aim.
    Place rotor on that axis and panels on that rotor top. Place also a camera to aim the sun before setting rotor RPM.
    Than do as @Sinbad said: set rotor rpm = 1/day duration (in minutes).
    And your panels will work at near 100% output.
    The only problem is rotor RPM is rounded to 5 degrees after point, so you will need a little correction from time to time.

    I'm doing this thing on this video near 5:00 (it's not in English, but it's easy to understand, what im doing).
     
  12. Harrekin

    Harrekin Master Engineer

    Messages:
    3,077
    Dude with all due respect, this is the programming section, not the "Download a mod to bypass" section.
     
Thread Status:
This last post in this thread was made more than 31 days old.