Games w/ Gravity... scripting odd gravity effects

Here’re some questions for the crew here at the forum - maybe someone has already solved this little issue…

How do you script the kind of gravity you might encounter from a space game - essentially, when you get close to certain things (planets, asteroids, etc) you get pulled towards them.

I’m not talking about simulating orbital mechanics or anything that complex, just something as basic as scripting a distance based trigger that causes colliders to accellerate towards the center of a given mesh, regardless of their facing or other orientation in regards to that mesh.

Even, perhaps, an FPS situation where a player could literally run ‘around’ an asteroid?

Any ideas?

(also, can Unity directly affect the vertices, etc of a mesh? Morph it somehow beyond just basic scaling and position changes?)

I only have Indie - so I’m out of luck on any solutions that require Pro.

The procedual examples folder has some mindblowing vertex manipulation stuff.

The member called Lallander said to me once he had centralised gravity sussed…

Good luck
AC

Procedural examples?

I’ll check it out.

http://forum.unity3d.com/viewtopic.php?t=4021

at the end of the thread joe gamble posted a script he said works for what he needed. i didn’t try it. iirc it’s distance based rather than gravity and it doesn’t take into account normals - so your character won’t follow the slope of a hill.

in the same thread, i posted an incomplete script that takes normals into account and should work for following the surface of an odd terrain. it uses force to fake gravity towards the center of the object. mine doesn’t work below the equator though. vector3.up doesn’t want to look down. haven’t had a chance to get back to it though. so you’d need to tweak…

And just to make it clear, this is all possible with Unity Indie.

Unity Pro is really cool, but mainly adds graphical goodies, low-level extensibility (raw OpenGL calls, C++ extensions)… and of course making games for Windows.

d.

I figured I could do most things in Indie no problem - just wasn’t sure.

To calculate gravity that is distance dependent you can use the following formula:

Fg = ( G * m1 * m2 ) / (r * r)

where:
m1 is mass of object 1 in kg
m2 is mass of object 2 in kg
r is the distance between the 2 objects
Fg is the force of gravity between the 2 objects
G is the gravitational constant

gravitational constant = 6.67300 × 10-11 m3 kg-1 s-2

I haven’t written any code for this but that’s the formula you would use.

that gravitation constant didn’t show up correctly

gravitational constant = 6.67300 × 10 -11 m3 kg-1 s-2

that 10 -11 is 10 raised to the -11 power
kg-1 is kg raised to the -1 power
s-2 is s raised to the -2 power