#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
GrappleHook.Grapples = {}
GrappleHook.HookModel = "hook"
function GrappleHook.addGrappleHook(weapon, shipHit)
local newGrapple = {}
--Don't add grapples if
--(1) Nil was passed
--(2) Weapon is dead
--(3) Weapon has no parent
if not weapon or not weapon:isValid() or not weapon.Parent:isValid()
return
end
--This is inaccurate - no real way to tell where this
--grapple came from on the source ship right now, besides
--explicitly telling it in the script
newGrapple.startShip = weapon.Parent
newGrapple.StartLocalPosition = ba.newVector(0, 0, 0)
--This is more accurate
newGrapple.EndShip = shipHit
newGrapple.EndLocalPosition = weapon.Position - shipHit.Position
--I don't remember if this is right or not
newGrapple.EndLocalOrientation = weapon.Orientation * shipHit.Orientation:getTranspose()
table.insert(GrappleHook.Grapples, newGrapple)
end
function GrappleHook.doFrame()
for k,g in pairs(GrappleHook.Grapples) do
--Renders grappling hook in the same position that it hit at
gr.drawModel(GrappleHook.HookModel, g.Endship.Position + g.EndLocalPosition, g.EndShip.Orientation * g.EndOrientation)
end
end
]
$Application: Freespace 2
$State: GS_STATE_PLAY_GAME
$On Frame: [
GrappleHook.doFrame()
]
$Application: Freespace 2
$Weapon Class: Grapple hook
$On Ship Collision: [
GrappleHook.addGrappleHook(hv.Weapon, hv.Ship)
]
#End
Something like that. That's more thinking out loud than anything tried-and-true - I haven't tested it, so it may even have some parse errors - but you can at least use it to get started. Right now it looks like the main limit you might run into is a lack of being able to get a normalized vector to represent the facing of one object to another.
That might just be my own sketchy math knowledge in this department, though, and you could certainly write those functions if they aren't built-in already (and you know about 3D vectors).