Author Topic: Debris and Gravity  (Read 11004 times)

0 Members and 1 Guest are viewing this topic.

Offline Black Wolf

  • Twisted Infinities
  • 212
  • Hey! You! Get off-a my cloud!
    • Visit the TI homepage!
Is it possible to script in some sort of system where by debris is affected by gravity? ATM if you put a mission in an atmospheric skybox, the debris flies off ala zero G, which kind of kills the immersion a little bit. It'd be nice to have it fall down instead.

Possible?

[EDIT]I have tried to look into this myself, for the record, but scripting and programming is something I've had zero experience with. I got as far as isHull, and then realized I had no idea how to apply it :\.
TWISTED INFINITIES · SECTORGAME· FRONTLINES
Rarely Updated P3D.
Burn the heretic who killed F2S! Burn him, burn him!!- GalEmp

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
For bigger debris bits it is possible to do. For the small debris shards i'm not sure
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline m!m

  • 211
It actually very easy to implement :P
See this:
Code: [Select]
#Conditional Hooks

$Application: FS2_Open
$On Frame:
[
globalG = 9.81
for i=1,#mn.Debris do
local vec = ba.createVector(0, -1, 0)
vec = vec * globalG / 50
mn.Debris[i].Physics.Velocity = mn.Debris[i].Physics.Velocity + vec
end
]

#End

Gives cool results with the new mediavp effects ;7
« Last Edit: October 19, 2010, 10:20:29 am by m!m »

 

Offline Sushi

  • Art Critic
  • 211
I imagine it's easier to do with debris than with ships, since with debris, you don't have to worry about damping messing up your gravity math. :)

You may want to consider including some sort of "drag" factor as well, so the debris reaches terminal velocity instead of accelerating forever...

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
What about landscape? Once debris hit landscape, it will contnue to ram it. It is unevitable, I guess?
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline Black Wolf

  • Twisted Infinities
  • 212
  • Hey! You! Get off-a my cloud!
    • Visit the TI homepage!
Debris tends to blow up when it collides with anything.

Cheers m!m, I'll try this out tonight :)
TWISTED INFINITIES · SECTORGAME· FRONTLINES
Rarely Updated P3D.
Burn the heretic who killed F2S! Burn him, burn him!!- GalEmp

 

Offline Polpolion

  • The sizzle, it thinks!
  • 211
    • Minecraft
Code: [Select]
globalG = 9.81

Well it works for Earth at sea level. :p

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Hmmm... Perhaps we could have variable geometry or a sexp which could set the value to be used by the script?
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Hmmm... Perhaps we could have variable geometry or a sexp which could set the value to be used by the script?

May be possible for the script to simply read a SEXP variable.

 

Offline ShadowGorrath

  • Not funny or clever
  • 211
Possible to make a script that makes a fighter/bomber start falling down if the speed is too low? I currently do it via events in FRED, but would be much better if it was in a script form and worked gradually.

 

Offline m!m

  • 211
Possible to make a script that makes a fighter/bomber start falling down if the speed is too low? I currently do it via events in FRED, but would be much better if it was in a script form and worked gradually.
This is possible and Nuke already showed it (check out his SVN) but the AI can't handle it as tries to use the normal FS-physics.

Hmmm... Perhaps we could have variable geometry or a sexp which could set the value to be used by the script?
Could be done like General Battuta says or via the script-eval SEXP.

 

Offline Black Wolf

  • Twisted Infinities
  • 212
  • Hey! You! Get off-a my cloud!
    • Visit the TI homepage!
Oh! Dude! :D

Once I fiured out how to apply this only to individual missions, man - so cool :) **** looks awesome blowing up now :D

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.

Thanks muchly :D
TWISTED INFINITIES · SECTORGAME· FRONTLINES
Rarely Updated P3D.
Burn the heretic who killed F2S! Burn him, burn him!!- GalEmp

 

Offline m!m

  • 211
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:

Code: [Select]
#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  :nervous:
« Last Edit: October 20, 2010, 11:40:20 am by m!m »

 

Offline Sushi

  • Art Critic
  • 211
What happens if you use this to apply gravity to ships?

 

Offline m!m

  • 211
Basically it would work but it will result in funny effect when the AI tries to get to a ship or a waypoint  :D

 

Offline Sushi

  • Art Critic
  • 211
Basically it would work but it will result in funny effect when the AI tries to get to a ship or a waypoint  :D

I don't suppose I can talk you into modifying the script so that it affects any ship with the "affected by gravity" flag set? :)

 

Offline m!m

  • 211
I don't suppose I can talk you into modifying the script so that it affects any ship with the "affected by gravity" flag set? :)
Well, AFAIK there's no possibility to access the flags from scripting but there's that neat SCP-badge right under your name so could you maybe make it available or help me find where I can find the flags in the code so I can do it on my own? :)

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Say...

Fringespace has a need for "gravitized" objects... would it be possible to develop this into "point gravity" within a specified object, and then use a scrpit, whether it's based on Newton's Law of Gravitation or something else (a variable gravity system dependant on range) , to ramp up the intensity of gravity upon a given target, whether it's the player ship or his wreckage?
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 

Offline Sushi

  • Art Critic
  • 211
I don't suppose I can talk you into modifying the script so that it affects any ship with the "affected by gravity" flag set? :)
Well, AFAIK there's no possibility to access the flags from scripting but there's that neat SCP-badge right under your name so could you maybe make it available or help me find where I can find the flags in the code so I can do it on my own? :)

The flag you want is SF2_AFFECTED_BY_GRAVITY. If you can't access it from scripting, though, that's a problem. Since I know practically nothing about the scripting code, I have no idea how to fix it, but hopefully that can be rectified (or someone else can do it :p).

 

Offline m!m

  • 211
Ok, got a function up that works (patch is attached).
Using this the script can apply the gravity on every ship that has this flag.

[attachment deleted by admin]