Backspace causes a crash, sim.lua line 84: attempt to get lenght of 'varPlanets' (nil).
Do you use Euler integration to calculate the orbits?
If so, and you're still interested in playing around with gravity I can recommend having a look at fourth order Runge-Kutta integration:
http://en.wikipedia.org/wiki/RK4
I just found a nice explaination (far better than I could ever write it probably) on why it is superior here:
http://gamedev.stackexchange.com/questi ... nt-gravity
I implemented it a while back, this might be easier to read than the pure mathematical approach:
Code: Select all
local function rk4( object, gameSpeed )
local k1, l1, k2, l2, k3, l3, k4, l4
local _mass, _position, _speed, _toOrigin = object.mass, object.position, object.speed, object.toOrigin
k1 = gameSpeed * _speed
l1 = gameSpeed * accelerationToOrigin( _toOrigin , _mass)
k2 = gameSpeed * (_speed + l1/2)
l2 = gameSpeed * accelerationToOrigin( _toOrigin + k1/2 , _mass)
k3 = gameSpeed * (_speed + l2/2)
l3 = gameSpeed * accelerationToOrigin( _toOrigin + k2/2 , _mass)
k4 = gameSpeed * (_speed + l3)
l4 = gameSpeed * accelerationToOrigin( _toOrigin + k3 , _mass)
local position = _position + k1/6 + k2/3 + k3/3 + k4/6
local speed = _speed + l1/6 + l2/3 + l3/3 + l4/6
return position, speed
end
The local variables k1, l1, and so on only serve readability. You could also do it all in one big ugly term.