The only issues I have are that it doesn't always quite work right - very occasionally ou still have bits of debris that'll float away - I think this occurs when they bounce of the ground - but I can so deal with that - it's too awesome not to.
I have no idea what causes this as the script doesn't make a difference between debris.
EDIT: I think I found what was wrong. The script left out the first debris so the gravity wasn't applied.
And I added a few things that make it possible to control the gravity constant and also it's possible to simply disable the script from FRED and I also tried to include some kind of landscape mechanism, see below:
#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
function indexOf(t,val)
for k,v in ipairs(t) do
if v == val then
return k
end
end
end
function g_setG(value)
if type(value) ~= "number" then
ba.warning("Invalid type given to g_setG!")
return
end
globalG = value
end
function g_enable()
enabled = true
end
function g_disable()
enabled = false
end
function g_sGr(value)
local ship = mn.Ships[value]
if ship == nil or not ship:isValid() then
ba.warning("Invalid value given to g_sGr")
return
end
groundShip = ship
end
ignoreDebris = {}
globalG = 10
enabled = true
groundShip = nil
]
$On Debris Collision:
[
if hv.Self:getBreedName():lower() == "ship" and hv.Self == groundShip then
hv.Debris.Physics.Velocity = ba.createVector(0,0,0)
table.insert(ignoreDebris, hv.Debris)
end
]
$State: GS_STATE_GAME_PLAY
$On Frame:
[
if globalG and globalG <= 0 or not enabled then
return
end
for i=0,#mn.Debris do
if indexOf(ignoreDebris, mn.Debris[i]) then
return -- Don't apply gravity on things we ignore
end
local vec = ba.createVector(0, -1, 0)
vec = vec * globalG / 50
local newVec = mn.Debris[i].Physics.Velocity + vec
mn.Debris[i].Physics.Velocity = newVec
end
]
#End
Interaction is possible via the script-eval SEXP:
use
script-eval with
g_setG(<some numeric value> as first Argument to set the gravity constant,
use it with
g_enable() or
g_disable() to enable/disable the script
and use
g_sGr(<some ship name>) to activate the landscape mode for that ship though I'm not sure if it will work