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.

 

23 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

Leave a Reply

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