GravityEngine

Gravity Engine V1.4

Full documentation and tutorials: Online Info

Gravity Engine brings full gravitational interaction for objects and particles to Unity. Masses and velocities are assigned to objects and Gravity Engine does the rest. It is highly tune-able allowing trade-offs between game play and physical accuracy.

Orbits can be defined and viewed in the scene editor.

Orbits resulting from spaceship velocity changes can be predicted and illustrated:
Screen Shot 2016-09-03 at 5.55.47 AM

Unity WebGL Orbit Prediction Scene

Custom planetary systems can be built or random ones may be created:
Screen Shot 2016-09-03 at 5.56.08 AM

Additional tutorials are available on the NBodyPhysics YouTube Channel.

 

30 thoughts on “GravityEngine

  1. Musketeer

    Bro you probably should target game maker’s interest instead of simply introduce orbit models…
    Go play Kerbal Space Program and some other gravity games and think about what Unity users actually want…
    For me, I need an gravity system suitable for interstellar combat, and properly optimized control code for spaceships in this environment is what I need next after a gravity system.
    I also need to optimize the law of forces deeper because the usual gravity law might not be the funnist configuration for space wars. Fun parts can come out of reality but usually not raw reality. so laws should be left for changing.

    Most Unity users use it for games, not for science. So do your plugin. Your plugin really has a potential but you need to rethink about it. If I am you, I would set my target as : a system that some like Kerbal Space Program might use it for producing games easier.

    Reply
    1. musgrave.peter@gmail.com Post author

      I appreciate you taking the time to provide feedback.

      I do plan on making the core code available – so developers can change the law of gravity if they wish. [EDIT: All code is available as of version 1.1]

      The tutorials perhaps over-emphasize the ability to create orbits. The asset will allow arbitrary (non-orbit) operations and does demonstrate how to adjust spacecraft orbits.

      Part of the challenge is that rocket science is, well, rocket science. Predicting the interactions of even three bodies is legendary as a source of chaotic motion. I do have a thread for what features could be added http://forum.unity3d.com/threads/released-gravity-engine.406402/. I welcome more discussion there.

      Reply
    1. musgrave.peter@gmail.com Post author

      Cool link. Thanks for that.

      Good advice to revisit Kerbal as well. I am looking into creating some scripts that show a projected orbit for a velocity change. I would like to then move on to transfer orbit/rendezvous maneuver sequence calculations – but I’ll need to learn some stuff to get that going.

      Reply
      1. Musketeer

        Great
        Predicted trajectory of a moving object in complex gravity environment is sth I haven’t figure out how to get it done. Looking for your solution.

        Reply
      2. Musketeer

        Great
        Predicted trajectory of a moving object in complex gravity environment is sth I haven’t figure out how to get it done. Looking forward to your solution.

        Reply
  2. Philip Tarpley

    Hey, I just got Gravity Engine. It is pretty cool, but it appears that all properties from NBody/Orbit scripts are stored by the GravityEngine behaviour on start, and thus cannot be changed during the simulation?

    The asset would have much more utility as far as games/simulations go if the NBody/Orbit props could be dynamically changed to allow seeing how the system changes if a body’s mass/orbit changes.

    Reply
    1. musgrave.peter@gmail.com Post author

      Hi Philip,

      Thanks for the feedback.

      Currently you can change the velocity of a body dynamically (which will change the orbit). I had not thought in terms of changes to the orbital elements (they are currently used only to set the initial velocity) – but that is something I will look at.

      Changing the mass is something I have been meaning to do. I’ll put it in the next update.
      [Edit: This is available in version 1.2]

      I hope to submit the next update for review in about 1 week. It will have orbit projections, random system generation and some minor fixes/additions.

      Reply
  3. Christopher Batih

    Hi there,

    I really like the look of this and want to make a purchase, but I have a couple of questions.

    Can I use this to simulate the movement of an object from the surface of a body to circular orbit? A spacecraft launch for example.

    Can I use this toolkit to simulate a hohmann transfer between two bodies?

    Thank you.

    Reply
    1. musgrave.peter@gmail.com Post author

      Hi,

      Apologies for the slow response – the comment pending emails to me seem to be broken.

      Yes, the asset can be used for hohmann transfers via the apply impulse function in the engine.

      I have not yet done much with starting from a surface. I think there will be a bit of new code to simplify the shift from non-orbital motion into orbital motion – so I expect I will need to make some modest changes.

      I am currently making modifications to support a variety of real-world units (currently the unit system is dimensionless with G=1 but several users have expressed an interest in entering info in kg, km, AU etc. and having Gravity Engine do the conversions).

      Reply
  4. Rahul Jethwani

    Hello

    I have just purchased your engine recently, and I must say I am impressed. I do however, have certain queries with which I hope you can help me

    We are using it for educational purposes to train people with the concept of orbit and gravity. We want to show the effect of what happens if the velocity of the satellite (in this case the planet) is increased at runtime (orbit-raising), or the mass of either the planet or its satellite. What would be the best way to make changes to implement this feature according to you? Will the engine be able to deliver our requirement after we make the changes?

    Thanks
    Rahul

    Reply
    1. musgrave.peter@gmail.com Post author

      Hi Rahul,

      There is a tutorial scene that should accomplish what you are asking. I seem to have failed to link it properly on the docs page – apologies for the omission.

      Take a look at https://www.youtube.com/watch?v=b4sunmCgXIw&t=2s

      Velocity can be changed at runtime with GravityEngine.instance.ApplyImpulse(…)

      Feel free to contact me at the support email if you have further question.

      Reply
  5. Daniel

    I love this system! However I’ve been suffering from performance issues (less then a frame per second) when I have one sun and two planets. Any idea on why this is?

    Thanks!

    Reply
    1. musgrave.peter@gmail.com Post author

      That is unexpected. If you can make a sample scene available to me via the support email (nbodyphysics@gmail.com) I’d like to take a look.

      Failing that if you can provide the positions, masses, velocities of the objects and any changes to the GravityEngine defaults I can try and duplicate your issue.

      Reply
  6. hersfeldtn

    Very interested in this project, a couple questions:

    -Is it possible to specify, for a particular object, which bodies are influencing it? So you could, for example, have a spaceship in solar orbit only influenced by the planets, and not by all their moons?

    -How difficult would it be to implement an orbit predictor based on n-body physics for a limited period ahead? Would it help if I keep all natural bodies in Kepler orbits?

    Reply
    1. musgrave.peter@gmail.com Post author

      1) Can you specify which bodies influence…
      If you gave e.g. all the moons zero mass, then they would stay in orbit around their planet and not influence other bodies. (They could be either NBody evolution or Kepler orbits).

      2) The current orbit predictor uses a single other mass as the environment. To do more than this it would be necessary to run the simulation ahead and track what happened and record it, then reset back to where you were. This could be done by spinning up another integrator for just the bodies of interest – but this is currently not supported. I’ll give it some thought….not sure how CPU-feasible it would be.

      Reply
      1. hersfeldtn

        1) Is there any way to do this without changing the entire system? Ideally I’d want to be able to place multiple spacecraft at different points without each one having to worry about all the bodies in the system.

        2) If it helps, I know that Children of a Dead Earth manages to do predictions of this type, but so far I haven’t been able to figure out how.

        Reply
        1. musgrave.peter@gmail.com Post author

          Is the concern about limiting interaction to local bodies about CPU effort or predictability?

          If it’s predictability, one other option would be to have a force law that was gravity within a specified radius and then was zero outside of it. With the custom force laws this could be done fairly simply.

          Reply
          1. hersfeldtn

            CPU effort is the big concern, although predictability also helps. The project I’m considering would, at minimum, have dozens of spacecraft moving through the solar system populated with maybe a hundred bodies. I’m trying to find any way to reduce the CPU load without resorting to patched conics.

  7. musgrave.peter@gmail.com Post author

    One approach used in more sophisticated NBody codes is to make a tree-based code. Each body interacts one on one with bodies in the same “box” and the effect of other boxes is based on the center of mass of the bodies in those boxes. As boxes get farther away, they get bigger.

    Another approach would be to move this into a GPU compute resource.

    It would be fun to add these to Gravity Engine – but it is nothing I can commit to in the near-term.

    Reply
    1. hersfeldtn

      One last question, then I promise I’m done:

      Would it be particularly problematic to nest instances of GravityEngine? So you could, for example, place an empty object at the barycenter of each planetary system with its total mass, then put another instance there to handle that planet’s moons, with spacecraft shunted between them when they pass into the hill sphere?

      Reply
      1. musgrave.peter@gmail.com Post author

        Always happy to talk about gravity.

        Yes, I think that’s something that is workable. I just made a scene with two GEs (needed a slight hack, to defeat a check for this). The issue is that if a body is in more than one GE then two different engines are trying to update it’s position. It should not be too hard to find a way around this – maybe tag an object with the name of the engine that should move it. I’ll tinker a bit in the next week or two. Ping me on the support email if you want an update.

        BTW – picked up Children of a Dead Earth. Early days – but I do like what they do with orbital mechanics. I had the frame of reference change on the GE Trello board already – it’s fun to see that work.

        Reply
  8. Peter D Wilson

    Surely asked before but, what comfortable compute power do I need to enjoy GravityEngine. I’m a Mac aficionado?

    Reply
    1. musgrave.peter@gmail.com Post author

      The compute power needed really depends on how many objects will be interacting: number of massive, massless and particles in the scene.

      Typically on my 2015 Mac running a dozen or so massive bodies and several thousand particles is never an issue, but I have not yet probed the upper limit. A performance assessment scene is on my list of features to add.

      If more performance is needed there are options to make some bodies massless, or put them in fixed orbits.

      Reply
  9. Ian George

    Hello Yes this asset looks very interesting and if it could be adjusted for PC games I think this may be exactly what I need but I do wish to know if I can use surface vehicles and build bases/cities on the planets as I have a few ideas for several games the first being Battlezone 98/ 2 /Crysis /Savage/ /Uprising 1st person Shooter FPS R.T.S Games where you plane build fight and mine on a planet or even an asteroid or even a comet body and then you can take to the stars and fight in a Freespace/Wing Commander/ Eve : Valkyrie style battle with Giant Space Cruisers and Space Battleships and small one man space fighters and bombers capable of entering planetary atmospheres and fighting there.

    What I wish to know will there be the capability of creating planetary atmospheres and having sea cruisers and frigates and battleships and cruisers and carriers and submarines on Earth style planets? And I noticed that you mentioned that you would be making irregular body shapes to be used on the planetary surfaces how far are with that ? Also will it be possible to import your own planets to use with this asset ?

    Reply
    1. musgrave.peter@gmail.com Post author

      Thanks for your interest.

      The gravity engine is better suited for space-level insteractions (planets, ships etc.) and not near surface interactions. There is no direct support for atmospheres – but there is an example scene that shows how to setup decay in an orbit – which will accomplish this.

      Based on your description (near planet gravitation field, surface interactions) gravity engine is not a great fit.

      (I am interested in a surface gravity of weird surfaces asset – but it is still just an idea at this point.)

      Reply
      1. Ian George

        Ahh what a shame as I see on your asset store page someone else was interested in That and I am definitely interested in fighting in Space and fighting on on a planet on the same level I see some games like Empyrion Galactic Survival http://empyriongame.com https://www.youtube.com/watch?v=vI-7IzZ4Akc can already do this and I would like this for my games I shall also leave some links to the other games I have mentioned so you get an idea of what I am talking about I am also interested in your ”weird surfaces” idea what exactly is that then ?

        Empyrion Galactic Survival
        http://store.steampowered.com/app/383120/Empyrion__Galactic_Survival/
        http://empyriongame.com
        https://www.youtube.com/watch?v=vI-7IzZ4Akc

        Battlezone 98 Redoux
        http://www.rebellion.com/games/battlezone-98-redux
        http://store.steampowered.com/app/301650/Battlezone_98_Reduxhttps://www.youtube.com/watch?v=Bp57Lo2grfM/
        https://www.youtube.com/watch?v=XNysGJZKmtQ

        Battlezone II: Combat Commander
        https://en.wikipedia.org/wiki/Battlezone_II:_Combat_Commander
        https://www.youtube.com/watch?v=PKCH1NoC3jQ

        Uprising Join or Die
        http://store.steampowered.com/app/465360/Uprising_Join_or_Die/
        https://www.youtube.com/watch?v=rDVZ6hBWAw0
        https://www.youtube.com/watch?v=v4WQnNkNOaE

        Uprising Lead And Destroy
        http://store.steampowered.com/app/514050/Uprising_2_Lead_and_Destroy/
        https://www.youtube.com/watch?v=4BVl9iQa1Xw

        Savage Resurrection
        http://store.steampowered.com/app/366440/Savage_Resurrection/
        http://store.steampowered.com/app/366440/Savage_Resurrection/
        https://www.youtube.com/watch?v=2L5VhIvHo1U

        Savage: The Battle for Newerth PC Games Trailer
        https://www.youtube.com/watch?v=bu1EE9pIers
        https://www.youtube.com/watch?v=xtSudF4hduw

        Crysis
        http://store.steampowered.com/app/17300/Crysis/
        https://www.youtube.com/watch?v=xvfVmlVcnJI
        https://www.youtube.com/watch?v=UMHgBplll8Q

        Decent Freespace
        https://steamcommunity.com/app/273600
        https://www.youtube.com/watch?v=NJ-xcgBL1mY
        https://www.youtube.com/watch?v=OdwMna9GEmg

        Freespace 2
        http://store.steampowered.com/app/273620/Freespace_2/
        https://www.youtube.com/watch?v=khIWdolT9xY
        https://www.youtube.com/watch?v=rZuA9zvxs0Q

        Wing Commander 3
        https://www.youtube.com/watch?v=RpxItq_r7to
        https://www.youtube.com/watch?v=xg4SZ-bFt44

        Eve : Valkyrie
        http://store.steampowered.com/app/538870/EVE_Valkyrie/
        https://www.youtube.com/watch?v=7iM31NDkbM8
        https://www.youtube.com/watch?v=iDhFpeYFbL8
        https://www.youtube.com/watch?v=3SI1CB4rcf8

        And with my game you would be able to walk about on Space Carries and Space Battleship/Cruiser Frigates e.t.c in the 1st person or 3rd person fly around in Space and fight in all areas get into and out of vehicles and fight in them and well with my game have an auto ject when your vehicle is destroyed yes kind of like Battlezone Hopefully you might make the Gravity Engine enabled so we could have surface vehicle and human /alien interaction with the planets I will definitely keep an eye on this asset with great interest

        Reply
        1. musgrave.peter@gmail.com Post author

          Thanks for taking the time to provide the references. I’ll try to find some time to explore them!

          Reply
        2. musgrave.peter@gmail.com Post author

          I didn’t answer your weird surface question.

          Motion *on* a 2-surface requires objects follow the natural geometry of the surface. I tinkered with this in my game Geodesic Asteroids, which I blogged about here and is available on iOS and Android.

          I am contemplating making this more general – and ideally supporting motion on an arbitrary smooth mesh or any of the standard mathematical 2 surfaces (torus, ellipsoid etc.). I think it would be fun to make an asset that allowed developers to do this.

          Reply

Leave a Reply

Your email address will not be published. Required fields are marked *