FreeSpace Releases > Scripting Releases

newtonian physics, well sorta

(1/7) > >>

by sorta i mean it obeys the law of inertia. it doesnt take mass into account yet. this only deals with velocity so rotations are the same as normal. i want to convert max velocity to max thrust output in newtons. in other words a ship at full thrust with the max thrust of 100 will produce 100 newtons of force at full throttle. then i can have acceleration rates based on force vs mass. il deal with that later. my current concern is in making flying newtonian playable. so now im focusing on making the nessicary gauges.

also this only works on the player, need to figure out how to deal with physics on a ship by ship basis, so that all ships operate them. im hopping i can tag objects with custom varibles, then its just a matter of loopong through the ships. the other thing is that it breaks the lead indicators, cause im setting the position directly rather than changing the velocity, which doesnt work. could probibly just use wanderers lead code, which ive butchered into my scripts till i wright my own.

anyway heres the code, id advise using a ship set up for 6dof flight (with slide and rear thrust enabled). you can use any ship but youl have to come about to slow down.

--- Code: ---#Global Hooks
--[[======= function defs =======]]--

setscreenvars = function() --scalers and constants for multi res support
local w = gr.getScreenWidth()
local h = gr.getScreenHeight()
local cx = w/2
local cy = h/2
local wf = 0
local hf = 0
local awh = 0
local hires = false

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false

return w,h,cx,cy,wf,hf,awh,hires

round = function(number) --rounds to nearest whole number, for some stupid reason, lua doesnt have this function
local W,F = math.modf(number)
if F < 0 then
if F <= -0.5 then W = W - 1 end
if F >= 0.5 then W = W + 1 end

return W

prograderet = function(x,y,vel)
x, y = x*wf, y*hf --round theese, our vector gets jumpy


gr.drawGradientLine(x + (12*awh), y + (12*awh), x + (6*awh), y + (6*awh) )
gr.drawGradientLine(x - (12*awh), y - (12*awh), x - (6*awh), y - (6*awh) )
gr.drawGradientLine(x - (12*awh), y + (12*awh), x - (6*awh), y + (6*awh) )
gr.drawGradientLine(x + (12*awh), y - (12*awh), x + (6*awh), y - (6*awh) )

vel = tostring(vel)

gr.drawString(vel, x - (gr.getStringWidth(vel) / 2), y - (2*awh) )

w,h,cx,cy,wf,hf,awh,hires = setscreenvars()


player = mn.Ships["Alpha 1"]

if player:isValid() then
if lvel == nil then lvel = ba.createVector(0,0,0) end
lvel = lvel + ( player.Physics.VelocityDesired * 0.01 * ba.getFrametime() )
wvel = player.Position + lvel

lmag = lvel:getMagnitude()
lmag = lmag / ba.getFrametime()
gr.drawString( round(lmag), 100 ,100)

Vx,Vy = (wvel + (lvel*lmag) ):getScreenCoords()

player.Position = wvel


if player:isValid() then
if Vx then prograderet( Vx, Vy, round(lmag) ) end


--- End code ---

i set it up for real newtonian but its buggy as hell so im not gonna post it. it takes the models mass field into account. a ships max velocity converts over directly to max thrust in newtons. i did find out that to get space shuttle ohms burn equivelant acceleration on a ship with a mass of about 7500 thakes about 3800 newtons. this is a huge geuesstimation though. i figure combat will reqire about twice that much thrust. might up the conversion to kilonewtons to make it more compatable for the average freespace fighter.

the major bugs are that i cant just directly modify the physics.velocity, seems freespace still wants to run its own physics on top of everything. i can change it but freespace just ignores it. so icheat and change the position directly. this breaks anything from lead reticles to collision detection. it also stutters alot. cause freespace wants to put the ship in one place and i want it somewhere else. i need a way to override the submarine-physics freespace uses to implement this right.

I noticed that there's a cheat code for FS2 that enables Descent physics.  Would this possibly be helpful to you?

Eh? How come no one else ever heard of this?

Unknown Target:
It's always been there, heh, it's on most sites that have cheats for FS2. :)


[0] Message Index

[#] Next page

Go to full version