Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: Scooby_Doo on March 05, 2013, 11:59:16 pm

Title: Rotating animation script (alpha build)
Post by: Scooby_Doo on March 05, 2013, 11:59:16 pm
Before I stall any longer here's the animation script. I haven't got everything I wanted in it yet, but there's enough for thrust vectoring, thrust nozzles and landing gear systems.  Also if someone wants to write this in a more understandable instructions please do!!!

This is an alpha build so it's probably buggy and not the best of handling everything, but it's a start.
There's a few things you must do beforehand to get everything working.

1. The subobject's axises must be aligned with that of the ships (i.e. the subobjects x axis must be parallel to the ships x, same for y & z). If they're not they won't rotate correctly (in fact they'll rotate on the ships axis rather than the subsystem's) If someone can find a solution for this please let me know! 

 If the subsystem's doesn't match up, you must rotate them to be parallel.  Remember what those rotation coordinates are, you'll need them later!!!  Finally preform a x-form reset (or equivalent) to force it aligned.  Don't worry you'll be providing those angles later and will appear correctly in-game

2. The subsystem must be visible to fred (i.e. have a $special=subsystem and $name=blah) and the appropriate ship table entries.  Otherwise nothing will happen

3. copy the animation-sct.tbm into the tables folder and load it with your favorite editor (notepad++ hint hint)

4. Scroll down to ShipType:RegisterShip (about line 1278) 
Code: [Select]
function ShipType:RegisterShip ()

local ship = self:GetRealShip ()
if (ship.Class.Name == "F-104D Bearcat") then
self:RegisterBearcat ()
-- Add different ship classes as needed here
self:SetInitialOrientation ()
you'll need to add your new ship type here.  Let's say for example you made "GTSV Hercules Mk X"
you would add this:
Code: [Select]
elseif (ship.Class.Name == "GTSV Hercules Mk X") then
     self:RegisterGTSVHercules ()

Warning! Renaming your ship latter will require this to be altered to.! (Is there a way in lua to retrieve the $short name for a ship? that would be much safer)

5. Next we need to create the RegisterGTSVHercules.  Jump down to line 1451 (ShipType:RegisterBearcat ())
This is a template for your ship. copy this function (1456 to 1623) and paste it. Rename it to that function name (in this case "RegisterGTSVHercules"

6. There's quite a bit here you probably won't need.  If your looking to do landing gears the stuff in "testing == 1" is what you want to look at (1470-1583).  Thrust vectoring, nozzling is the second half (1586-1621)
I hope I left enough comments in there to help you.  There's two different ship models i used, one was my bearcat with landing gears and the other a box with vectoring engines.

Also remember back when I said to remember those coordinates if the axises didn't align, those go in the Offset.  The second parameter for RegisterLandingGearSubsystem, RegisterThrustVectorSubsystem, RegisterThrustVelocitySubsystem.  I.e. let's say you had a subobject "PortLandingGear"  that was off ship axis.  You rotated it till it was on.  Let's say (-10,0,0).  RegisterLandingGear... would look like this:
Code: [Select]
self:RegisterLandingGearSubsystem ("PortLandingGear" ba.createVector (math.rad (10),0,0),......
Note the angle is the negative if what we first saw.  We want the offset to be the angle from the ships (0,0,0) to where the subsystem should first show up as.  Hope that made sense

7. That should be it for lua coding! WHEW!

8. In FRED you'll want to luascript these functions:  OpenLandGear ("ShipName")  CloseLandGear ("ShipName") ToggleLandGear ("ShipName")

Ugh too big for code.  Grab it here:

Version 0.201

Version .2

Version .12

Version .11

Version .1
Title: Re: Rotating animation script (alpha build)
Post by: BlasterNT on March 06, 2013, 10:05:42 pm
Awesome.  Could you release the test models you used as an example?
Title: Re: Rotating animation script (alpha build)
Post by: Scooby_Doo on March 06, 2013, 10:28:24 pm
Yup, give me a couple minutes...

Alright here's everything:
There's two different models, the landing gear bearcat  and the thrust vectoring/nozzle. 
To switch to the bearcat model:
set TCI-Bearcat-shp.tbm   "$Pof file: TCI-Bearcat1.pof"
animation-sct.tbm   line 1463   "local testing = 1"

To switch to the thrust nozzle model:
set TCI-Bearcat-shp.tbm "$POF file: TCI-Bearcat.pof"
animation-sct.tbm line 1463  "local testing = 0"

it's not the best way but it works for me.  also there is no need to modify the mission file (i think i set the keys alt+q and alt+g to open/close the doors, they have no effect on the thruster version)

If you have any more questions, just ask!

Title: Re: Rotating animation script (alpha build)
Post by: BlasterNT on March 07, 2013, 01:38:40 pm
I'm getting the following error with the bearcat model:  "GetShipByName (name) Mismatch type <name>, needs 'string', got string"
Title: Re: Rotating animation script (alpha build)
Post by: Scooby_Doo on March 07, 2013, 10:35:07 pm
Fixed, there was an another  one.  My type checking routine wasn't looking for the right thing whoops.

Version 0.11 is up now.
Title: Re: Rotating animation script (alpha build)
Post by: Scooby_Doo on November 24, 2013, 12:09:01 am
I've updated it to 0.12  There was a bug with the thruster velocity,  afterburner angles were always used when afterburning, even if you didn't want it.  It now obeys your true/false request, although it might be a bit jumpy when going from zero to afterburner and back again.  One possible solution is to give  the afterburner position  the same position as the max speed position.
Title: Re: Rotating animation script (alpha build)
Post by: Scooby_Doo on June 26, 2014, 01:37:20 am
There seems to be a bug in the RemoveLostShips.  The game will crash when you kill a ship. Why the game is crashing is confusing me.

When I use the open/close/toggle landing gear I can search through the ships available ingame and choose the correct one (done simply via GetShipByName script).

Now when I look for ships that are no longer in the game, the list still exists and has all the correct entries, but when I try to retrieve an entry it's nil.

Code: [Select]
function ToggleLandGear(shipName)
assert (shipName ~= nil, "Error: CloseLandGear (shipName) shipName is nil")

local ship = shipList:GetShipByName (shipName)

Code: [Select]
function ShipListType:GetShipByName (name)
assert (name ~= nil, "ShipListType:GetShipByName (name) name is nil")
assert (type (name) == "string", "ShipListType:GetShipByName (name) Mismatch type <name>, needs 'string', got " .. tostring (type (name)))

for loop = 1, #self.shipAnimationList do
local ship = self:GetShip (loop)
if (ship:GetRealShip ().Name == name) then
return ship

return nil

Code: [Select]
function RemoveLostShips ()

debugs = #shipList.shipAnimationList
gr.drawString (debugs, 50,50)

local debugs3 = shipList.shipAnimationList [1]
gr.drawString (debugs3, 100, 150)

local debugs1 = shipList:GetShipByName ("Alpha 1")
gr.drawString (debugs1, 100, 50)

local debugs2 = shipList:GetShipByName ("Test1")
gr.drawString (debugs2, 100, 100)

In RemoveLostShips all those show (nil)... but I can still ToggleLandGear ("Alpha 1") and it works  :banghead:  :confused:
Title: Re: Rotating animation script (alpha build)
Post by: Scooby_Doo on August 24, 2014, 10:20:46 pm
Think I've finally cracked the problem with crash to desktop when a ship is destroyed.

Version 0.2 has been uploaded, hopefully no more problems with that. *crosses fingers*
Title: Re: Rotating animation script (alpha build)
Post by: Scooby_Doo on October 08, 2014, 02:53:19 am
Another bug fixed, Version 0.201. This time is was a stupid little error  :banghead:  When you forced the landing gears to close it would act as though they were opening.  I had CloseLandingGear call for opening LOL.

Also I learned in the ship table, the subsystem entry just needs the bare basics.  Don't put any rotation/animation info in, otherwise the subsystem can do some weird rotations that you don't have any idea why it's doing it.  Spent an hour trying to figure that one out.