Topic: Adding gravity to a planet

Hey! Now I'm doing a script for planetary gravity.

    core = getObject(core)
    planet = getObject(planet)
    player = getObject(player)



    playerpos = getPosition(player)
   
    corepos = getPosition(core)
   
    gravity = {playerpos[1] - corepos[1], playerpos[2] - corepos[2], playerpos[3] - corepos[3]}

Thinking that the player will be drawn to the core of the planet by subtracting there co-ordinates all the time, and that the physics-enabled-planet will provide ground to collide with.

This is my idea, but it doesn't work.

Re: Adding gravity to a planet

set the gravity to zero, set the objects physics and use "addCentralForce" :
http://wiki.maratis3d.org/index.php?tit … ntralForce

Re: Adding gravity to a planet

playerpos = getPosition(player)
   
    corepos = getPosition(core)
   
      gravity = {0, 0, 0}
   
    addCentralForce(player, {playerpos[1] - corepos[1], playerpos[2] - corepos[2], playerpos[3] - corepos[3]}, "local")
   

Like this?

Re: Adding gravity to a planet

I think it's the reverse, and not local :

force = {corepos[1] - playerpos[1], corepos[2] - playerpos[2], corepos[3] - playerpos[3]}


addCentralForce(player, force)

you also might need to normalize the force vector :

function getLength3d(vec)

    return math.sqrt(vec[1]*vec[1] + vec[2]*vec[2] + vec[3]*vec[3])

end

function normalize3d(vec)

    length = getLength3d(vec)
    vec[1] = vec[1] / length
    vec[2] = vec[2] / length
    vec[3] = vec[3] / length
    return vec

end

Re: Adding gravity to a planet

Thanks. smile