Announcement

Collapse
No announcement yet.

Simulate Planet Orbit?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Simulate Planet Orbit?

    Hello,
    My game is played on a tiny moon that has a diameter about 3km across. Strangely enough it was fairly simple to get a "tank"/car to run the whole way around it. lol, It actually looks and works kinda neat. With "Simulated Low Gravity" it covers up a lot of bad programming. The Tank bounces around just like you think it would in a low gravity environment. Im actually thinking of trying a low gravity asteroid racing game.

    What I want to try now is to have the moon that the players play on "Orbit" around a big planet. To add the atmosphere for the game. However, I'm keeping the entire game inside a 4km x 4km square. Everything seems to run fine at this size. As long as I stay inside this box, everything runs fine, at least so far.

    I have tried to rotate the planet around my small moon, but I'm just not getting it. I cant figure out a way to move the big planet, that makes it look like the small moon is the one that is actually moving.

    Basically my problem is that I cant move my little moon, because it will go out of the ue4 world size. So I have to move the big planet, where no players are playing. Its just a big sphere out there to look at, nothing else. I cant figure out the math to make the orbit right. Any Ideas?

    #2
    Well, the math is pretty simple, coincidentally I just made something like this yesterday.

    Code:
    Force = (mass of first body * mass of second body) / distance^2
    Then just apply the force into the direction of a body you want to orbit around.

    Here is the outcome:




    Is your problem just the world size or also that the moon can't move, since there are players on?

    In case it is just the world size, then consider scaling everything down and therefore convert units from cm to m for example. Depending on your game, that still leaves enough floating point precision and increases the size of your map by a factor of 100.

    Comment


      #3
      Well, you can just sketch out on paper how the moon would orbit around the planet. Then check out the relative position of the planet to the moon,and just do the movement. And the game changer propably, make the sky sphere (all the stars) be oriented same as the planet. This will give the feeling that the moon is moving, not the planet.

      Comment


        #4
        I solved orbiting problem by using rotate vector on axis node, getting the rotation of the object being orbited, isolating the axis I wanted it to orbit in.. and then applying the transformation to a lerp over time. You will likely need to subtract the position offset between the two objects and then re-apply it after the rotation.... I am not sure if such a thing exists but I imagine there must be some way to set up a preplanned path for that object using a spline or animation that requires no continuous calculations.... I assume you could also change the pivot of the orbiting object to the location of the object you intend to be orbited.
        Last edited by safetyman; 08-15-2014, 06:08 AM.

        Comment


          #5
          @safetyman:

          Faking an orbit is actually much easier than that. You could just create an blueprint and add your orbiting body as child. Then you only have to rotate its parent using either the rotatingMovementComponent thing or just rotate the parent per tick.

          Comment


            #6
            Ah yea that is simple! I knew there had to be an easy hierarchical solve.

            Comment


              #7
              Originally posted by DennyR View Post
              @safetyman:

              Faking an orbit is actually much easier than that. You could just create an blueprint and add your orbiting body as child. Then you only have to rotate its parent using either the rotatingMovementComponent thing or just rotate the parent per tick.
              Ah yea, thanks a lot. It works good enough, looks fine.
              And really simple and bug free.

              Comment


                #8
                o my GOD, your video is so cool! can you tell me how you do this in blueprint? thanks a lot!
                Website:www.phantomisreal.com
                Youtube: https://www.youtube.com/channel/UC0J...teUGFLma3dgljQ
                Twitter: https://twitter.com/Phantomisreal
                Steam: http://store.steampowered.com/app/578800
                Instagram: https://www.instagram.com/phantomisreal

                Comment


                  #9
                  Originally posted by DennyR View Post
                  Well, the math is pretty simple, coincidentally I just made something like this yesterday.

                  Code:
                  Force = (mass of first body * mass of second body) / distance^2
                  Then just apply the force into the direction of a body you want to orbit around.

                  Here is the outcome:




                  Is your problem just the world size or also that the moon can't move, since there are players on?

                  In case it is just the world size, then consider scaling everything down and therefore convert units from cm to m for example. Depending on your game, that still leaves enough floating point precision and increases the size of your map by a factor of 100.
                  Any chance on making a tutorial?
                  "A little bit of nonsense now and then is cherished by the wisest men..."
                  -- Willy Wonka

                  Smooth Zoom Camera Plugin for 4.24 here.

                  Comment


                    #10
                    Planet and moon do not need to obey physics, all they need to do is to be in right location at right time.

                    I solved this same problem few months ago:
                    first make blueprint that calculates all orbital movement normal way ie. planets orbit sun, moons orbit planets.
                    make new struct that holds planet transformation, and index of planet "parent" (or what body planet is orbiting)
                    For sun it will be 0,0,0 and index of parent -1 because sun is at origin of map and does not orbit anything
                    Planet will have: orbit_distance * 1,0,0 vector, and index 0 because it is orbiting sun
                    Moon will have: index of planet, and moon_orbit_distance *1,0,0 + planet starting location.

                    Now you calculate new locations for each body in loop.
                    to get final location you add parents current location to calculated one.

                    When you have nice little system rolling its time to some vector magic:
                    now you have everything moving relative to sun and sun is origin of world
                    you need to transfer your relative location to moon.
                    doing this is very simple:
                    get moon (or focused planet) location
                    and substract that vector from every location of every body,
                    place all in that new locations.

                    So you calculate your moon location like it was orbiting sun (normal way)
                    then you move everything by that distance
                    this way your moon lands in 0,0,0
                    and everything madly spins around it

                    ps. IF i dig out my old project from backup i may post working solution later today.

                    pps. do not worry about world size. observed unreal universe is about 10000 bigger than grid in editor
                    Last edited by Nawrot; 10-06-2015, 08:05 AM.

                    Comment


                      #11
                      Not to blow smoke up myself, but I spent the last year plus writing a scientifically-accurate (I know, because I worked with a ground-control station to make it) orbit system - so frankly this is one thing I'm pretty expert on.

                      If it helps at all, it's probably one of the hardest things I've ever done and absolutely not possible in Blueprint if you want to base it on real Orbital Mechanics, or simulate in non-realtime. There is unfortunately no easy simulation for real orbits, Orbital Mechanics itself IS the simulation. If you want a very basic approximation, you can probably do something like what has been suggested above, however - If you want to do ANY kind of orbit prediction, you absolutely have to use Orbital Mechanics because it's THE fastest way to do it. We can simulate around 100+ orbits on an Android device AND draw and render all the splines for the orbit prediction on those devices, so it's incredibly fast. Time Dilation will not help you predict orbits.

                      Our current system in our game uses the Two-Line Element (TLE) NORAD system, which is a set of 12 unique properties that completely describe an orbit and the object it belongs to. From these elements we do all the maths to generate the orbit, and ultimately, it's a product of 'Julian Time'. We can get Position, Velocity and all the other Orbital State vectors and Orbital Properties by feeding the simulation a 'Time', and the simulation tells us where an object will be in orbit at any given time (with some very close degree of precision). It's the same system that NASA / ESA use to track their Satellites from the ground.

                      Unfortunately, the TLE system is VERY prone to errors and in our case corruption - and was also built with the sole intention of a single, dominant body (the Earth). This means you can't just drop in several planets and have them realistically orbit each other, it's all based on Satellites orbiting the Earth based on their ECI. The TLE system can also only work for non-hyperbolic orbits (IE, they're in orbit, not escaping orbit or crashing into the Earth).

                      I'm now writing a new system (and btw, a markerplace plugin eventually!) which uses Spheres-of-Influence, which allows you to place a bunch of bodies in a space and have them all act accordingly. Kerbal Space Program uses something similar I believe and it's simulation is very solid (major props to the people that worked on it), that will still enable prediction. It is however, really frigging hard, so don't expect to see it for a few months yet.

                      Also, there is the issue of scale - we use 1cm to 1Km in Unreal, but we can't get our Satellites small enough unfortunately, or we soon hit floating point errors. We could rewrite some of the engine code to work at double-precision world space coordinates, but we didn't need it for this game.

                      Comment


                        #12
                        Jamsh can you point me to formulas for calculating planet positions in solar system? Not overly accurate, all I need is their orbit parameters and calculate where they are given date. Wikipedia is quite silly with that information, or my search skills failed me. I can find all orbit parameters, but not positions of planets (and most moons in solar system) on some day.

                        I could find when great conjunction happened and calculate it from that, but then again what exact direction from sum it all happened? ( I want to place star constellations in right direction later on ). Accuracy should be about 1 day or so.

                        Comment


                          #13
                          Just reading the whole thread, my solution is probably overkill for what you're doing so a simple rotational movement should be enough or your case

                          @Nawrot - The best thing I can recommend (if you want accuracy) is using NASA's Eyes on the Solar System software. It's free and you can track to any period of time and find the real position of a Planet relative to the Sun I believe, I can't remember what other data it gives you. There are a whole bunch of simulations out there but NASA's one is probably the most easy to use and trustworthy.

                          There's also a bit of software called 'Digistar' that's designed for Planetariums, that shows accurate relative locations of stars and suchlike. There are databases all over the place for that kind of thing though which you can probably find.

                          The TLE system I mentioned is only suitable for Earth-Central Inertial (ECI) coordinates, so won't work for planets (well it might, but holy hell you'll get floating point errors). The planet position depends on the reference coordinate system. Most Planetary ones revolve around the Sun, but there are some that are relative to Earth etc. Unfortunately a lot of the very very smart people that do this stuff aren't great at building good UX websites haha, so a lot of what I found was after hours of trawling through google search. Wikipedia is a good start though so long as you're comfortable with the math.

                          But yeah if you just want to check reference against your own system, NASA eyes is what I'd recommend!

                          On a side note, I would *really* love to release this work as a plugin but Unreal won't be able to scale up to some scales, so things will be miniaturized. Realistically you'd need double or even quad-precision worlds to simulate some of this stuff at a 1:1 scale. It's amazing how big our little spec of space really is!
                          Last edited by TheJamsh; 10-06-2015, 11:37 AM.

                          Comment


                            #14
                            Thanks, no more blind searching.
                            I am making mobile game so accuracy is not that important user cannot see much on small screen.
                            I use that NASA software.

                            I did some experiments with location in unreal, and its fine up to full length integer for location, not sure how physics behaves there, but everything else (that i tested) works fine. Full length int is cube size of 10kx10kx10k of editor grids. I hope everything works fine in that area.

                            Comment


                              #15
                              Yeah 10K is okay, it's when you get into the 100K's (like ours did) that you start having issues!

                              Comment

                              Working...
                              X