playMaker

Author Topic: physics orbit  (Read 2783 times)

MIKMANNER

  • Playmaker Newbie
  • *
  • Posts: 10
physics orbit
« on: February 12, 2012, 07:46:49 AM »
Hi I'm trying to figure out how to make multiple objects (or multiple clones of objects) rotate around a sphere (like in our solar system) with physics. I can't figure it out at all, any help would be appreciated.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: physics orbit
« Reply #1 on: February 12, 2012, 01:44:19 PM »
Do you definitely need to use physics for this, or can you fake it?

To do it with physics you'd need to apply a force towards the sphere, and achieve a stable orbit with just the right velocity perpendicular to that force. If the body slows down it will fall towards the sphere, and if it speeds up it will fly away from the sphere. So achieving a stable orbit using just physics is tricky. But possible if you really need to do it correctly for gameplay/interactive reasons...

Otherwise you could just parent the objects to a pivot object at the sphere's position and rotate that pivot to rotate the object around the sphere. Each orbiting object could have its own pivot if they need to rotate at different speeds.

MIKMANNER

  • Playmaker Newbie
  • *
  • Posts: 10
Re: physics orbit
« Reply #2 on: February 12, 2012, 04:01:08 PM »
Thanks for the reply, yeah I'm trying to get a gravitation simulation to affect any rigidbody object. Similar to how New Orbit or Osmos behaves. If it is just a case of tweaking force around a centre position then that's cool I can work on that. I want mass or size to affect what the largest 'attractor' object is, so if you have say 20 objects in a scene and you randomly assign one of them to have a larger density then all other objects should then attract to it (and hopefully orbit if at a far enough distance) - I think the maths for this might be a bit beyond me.

In Construct I had a behaviour that did this as a plugin, I guess I shouldn't be so assuming that it'd be as easy in other programs haha

Thanks for the response.

Do you definitely need to use physics for this, or can you fake it?

To do it with physics you'd need to apply a force towards the sphere, and achieve a stable orbit with just the right velocity perpendicular to that force. If the body slows down it will fall towards the sphere, and if it speeds up it will fly away from the sphere. So achieving a stable orbit using just physics is tricky. But possible if you really need to do it correctly for gameplay/interactive reasons...

Otherwise you could just parent the objects to a pivot object at the sphere's position and rotate that pivot to rotate the object around the sphere. Each orbiting object could have its own pivot if they need to rotate at different speeds.