The physics will have to be fudged a little since in real space there is no maximum speed except C (speed of light). What we would really deal with is kinetic energy of which there is no maximum. Each object would have a set mass and the tractor beam would have a certain amount of pull. So if you were 10 tonnes and the object you were pulling was 1 tonne, you would be pulled towards it by 1/10th that it would be pulled towards you, etc.
So to make this work well in oolite, it would probably be fair to say that you can only use tractor beams on objects w/o shields. I don't suppose objects (ships, asteroids, bases, cargo, splinters, escape pods, etc.) currently have a "mass" value do they? If not, then the first step would be just to make it work on scoopables and give them all a mass of one tonne. The second step would be to fake a mass for ships (presuming derelict ships?) based upon their price and then just treat your own ship as immovable (for the sake of easy incorporation with game physics).
Anyway, it should probably have a maximum distance at which it is effective and then a maximum pull strength that it can apply. So perhaps your selected target must be a maximum of 8km for there to be any affect at all and an optimal range of 500m where the beam reaches full strength. The maximum affect would be to change the vector of the object in the direction of the delta of the two vectors (so the difference in between your ships location and the object's location) and by a maximum force that would change the velocity of a one tonne object by 5km/s or some such (again, using simplified physics). Of course, the beam should emit from your fuel scoop so as to pull in that direction.
The math is basically as follows:
Adjust the ship's coordinates to the mouth of the fuel scoop (I'm not sure exactly where that is or how it's calculated). So o is the object's vector and s is the ship's vector
Code: Select all
// constants
TRACTOR_MAX_PULL = 5000 // per second
TRACTOR_ENERGY_BASE = 1 // cost per second just for having it active (I don't know actual units used for energy)
TRACTOR_ENERGY_PULL = 20 // cost per second for pulling with max force
GAME_FRAMES_PER_SECOND = 60?
delta[x, y, z] = [o.x - s.x, o.y - s.y, o.z - s.z]
distance = sqrt(o.x * s.x + o.y * s.y + o.z * s.z)
if distance > 8000 then
// no effect
force = 0
else if distance < 500
// maximum possible effect
force = 1
else
// apply law of inverse squares
force = distance / 500
endif
delta.w *= force * TRACTOR_MAX_PULL / GAME_FRAMES_PER_SECOND
energy_used = (TRACTOR_ENERGY_BASE + TRACTOR_ENERGY_PULL * force) / GAME_FRAMES_PER_SECOND
// apply delta
// consume energy
EDIT: Changed energy to have a min usage per second and a consumption per force pulled.