Planet gravity using Ageia

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Planet gravity using Ageia

Post by Slaine »

Does anyone know the best way of doing this using PhysX? I cant seem to find any examples.

Many thanks.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

what on earth do you mean by planet gravity?

something for a space game where you want objects to gravitate towards an object such as a planet?

i don't think ageia supports objects having gravity so you'd have to set it up yourself.

it's not too hard though. there's an example which shows you how to do explosions, which is objects being pushed away from the centre of an explosion, all you need to do is the opposite, drag objects towards the centre of your planet object. So basically just copy the explosion example but instead of pushing things out drag them in with the opposite force which the explosion uses.
Image Image Image
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

JP wrote:what on earth do you mean by planet gravity?

something for a space game where you want objects to gravitate towards an object such as a planet?

i don't think ageia supports objects having gravity so you'd have to set it up yourself.

it's not too hard though. there's an example which shows you how to do explosions, which is objects being pushed away from the centre of an explosion, all you need to do is the opposite, drag objects towards the centre of your planet object. So basically just copy the explosion example but instead of pushing things out drag them in with the opposite force which the explosion uses.
LOL Sorry it was written very quickly, so it sounded childish :oops:

Yeah funny you should say that, I started playing with that very idea, see how it goes :)

Thanks.
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

if you want planetary gravity depending on where the player is ON the planet, just use as the gravity factor in the collision function, the player's position normalized ( assuming the center is at 0,0,0 ).
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

Mirror wrote:if you want planetary gravity depending on where the player is ON the planet, just use as the gravity factor in the collision function, the player's position normalized ( assuming the center is at 0,0,0 ).
No I'm setting up interstellar gravity wells, as in a whole system of planets. I've done this before with an algorythm, but I couldn't get the orbits correct, they were always elliptical, is in only the far out bodies are elliptical, Earth and it's moon are pretty much round, just wondering if using a physics engine will help, probably not.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Use generic forces, or use forcefields to generate "zones" of gravity.

PhysX should be able to handle things like that easily. See the water planet demo.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Johan
Posts: 32
Joined: Thu Jun 12, 2008 7:51 pm
Location: south africa

Post by Johan »

hope i dont sound stupid because im thinking of a newton thing i saw in the newton playground , magnetism maby
compulsive compiler
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

Johan wrote:hope i dont sound stupid because im thinking of a newton thing i saw in the newton playground , magnetism maby
Yeah I think it is Newton which has a nifty function to simulate multiple gravity, where you can place the gravity's anywhere, just thought PhysX might have it too.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Incidentally i did something very similar in my game with Physx the other day. I'm working on a boss which can suck you towards him, which is obviously the same as gravity and i got it working exactly the way i described above, by copying the explosion example and inverting the force.
Image Image Image
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Post by Slaine »

JP wrote:Incidentally i did something very similar in my game with Physx the other day. I'm working on a boss which can suck you towards him, which is obviously the same as gravity and i got it working exactly the way i described above, by copying the explosion example and inverting the force.
Excellent! So does this method have gradual increasing gravity? As in as you get closer the gravity increases, well actually, is that something to do with velocity? I might be confusing the two.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I should think it does because the explosion example did, closer you are to the explosion the stronger the force.
Image Image Image
night_hawk
Posts: 153
Joined: Mon Mar 03, 2008 8:42 am
Location: Suceava - Romania
Contact:

Post by night_hawk »

A simpler way (similar to the Explosion demo, but without copy-pasting it) would be to get the relative position of each node to your planet (node.position - planet.position), invert it (planet.position - node.position :) ), maybe normalize it and use it as a force added to that node. That seems like cheap and easy, no?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That's exactly how the explosion is done.
Image Image Image
night_hawk
Posts: 153
Joined: Mon Mar 03, 2008 8:42 am
Location: Suceava - Romania
Contact:

Post by night_hawk »

Indeed, but at least this way people implementing it will understand how it actualy works.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Obviously you haven't seen the explosion tutorial because the code is exactly the same as what you're saying, it's not hidden code, it's not a special way physx has of handling explosions it's just showing how forces such as explosions can be calculated and applied.
Image Image Image
Post Reply