Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: The basics of animating Ships - a cry for help  (Read 960 times)

Kermmander

  • Ensign
  • *
  • Posts: 3
    • View Profile
The basics of animating Ships - a cry for help
« on: January 29, 2023, 09:34:41 PM »

So after spiriting/kit bashing a decent number of ships together, and learning the basics of implementing custom ship, weapons and hull-systems into the game, I find myself at a cross road when it comes to the scripting more complicated parts of creating a mod.

https://www.reddit.com/r/starsector/comments/10lmiha/trojan_logistics_work_so_far/

What am i trying to do:
My intention is a series of "Qships"; being vanilla or logistic styled ships which through the use (ideally) a hull-mod initiated animation would shed or fold away door and covers to reveal weapons.

I read everything I can google, and attempted to source any kind of guide on how to even begin to approach such a task but to no avail. I have tried to pull apart SCI and Diable animations (which are just on an unbelievable level of amazing) but without understanding the basics of how to script the animations its meaningless to me.

Is there any guides available that I'm not finding, any  basic templates with a "fill in the gaps" type of approach or even better; anyone silly enough to assist me with the coding.

I'm a pragmatist so if the answer is "its beyond my skill-set and give up" that's also a reasonable answer (and ill just stick to what i know)
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: The basics of animating Ships - a cry for help
« Reply #1 on: January 29, 2023, 10:13:25 PM »

Hm. Don't hold your breath, but this is related to a project I've been working on off and on: making a framework to allow for easier animation of decorative weapons.

In the meantime, though, I'd suggest dropping the 'animation' portion and using decorative weapons that simply respond to the state of the ship. For example, a deco hull panel that covers a turret slot and, if a weapon is installed in that slot, replaces itself with an empty image. (Or perhaps the other way around would work better?)
Pair that with a built-in hullmod that adds cargo space if the weapon slot is empty, or perhaps reduces cargo space if the weapon is present, and you should have a good start on something that feels like it can be outfitted as a q-ship... if, perhaps, along similar lines to phase ships, where maybe it was stealthy at some point in the past, but modern sensor upgrades have overcome that.

See the decolib mod for an example of how to make weapon visibility changes that will be properly reflected in all screens (except the main map, but details of ships aren't really visible at that scale.) And then thank Alex for adding in the WeaponEffectPluginWithInit interface and its init method.
Logged
Wyvern is 100% correct about the math.

shoi

  • Admiral
  • *****
  • Posts: 650
    • View Profile
Re: The basics of animating Ships - a cry for help
« Reply #2 on: January 30, 2023, 12:09:19 AM »

what is the condition for the doors to be shed? getting within weapons range? the moment enemies are visible in the  fog of war? etc etc?

You will probably have to make a deco weapon with whatever number of frames your animation has. Then you'll need an everyframe script attached to that weapon that evaluates when it is time to open the doors, and when that condition is met increments the frame shown based off whatever your conditions are.

so a psuedocode-y impl would be like
Code
public class openDoors implements EveryFrameWeaponEffectPlugin {

    private boolean isIncognito = true;

//default frame, assuming frame 0 is w/ doors closed
private int frame = 0;
    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)
{
//theres stuff to shoot so we should open up the doors
if(enemiesAreInRange)
isIncognito = false;

if(!isIncognito)
interval.advance(amount);

//if we havent reached the last frame already, increment frame no.
if(interval.intervalElapsed() && frame < maxNumFrames)
frame++;

//set weapon frame to whatever current frame is
weapon.getAnimation().setFrame(frame);

    }
}

Logged

Kermmander

  • Ensign
  • *
  • Posts: 3
    • View Profile
Re: The basics of animating Ships - a cry for help
« Reply #3 on: January 30, 2023, 03:28:28 PM »

shoi that's far more understandable than what Ive been - incredibly helpful and thank-you for taking the time.

Having the doors open when in range is one possible option - i was also considering having a ship system to toggle them open/closed.

So I assume the next steps are to:
1. Have the door sprites individually drawn up and numbered 00 - 01 - 02 - ect.
2. Have your code below in a .java file in the scripts folder
3. Have the .wpn file "everyFrameEffect" referencing "openDoors"
Logged

Kermmander

  • Ensign
  • *
  • Posts: 3
    • View Profile
Re: The basics of animating Ships - a cry for help
« Reply #4 on: January 30, 2023, 03:30:03 PM »

Hm. Don't hold your breath, but this is related to a project I've been working on off and on: making a framework to allow for easier animation of decorative weapons.

Bloody hell mate - if you get that off the ground it would be game-changing!
Logged

shoi

  • Admiral
  • *****
  • Posts: 650
    • View Profile
Re: The basics of animating Ships - a cry for help
« Reply #5 on: February 01, 2023, 04:20:20 PM »

shoi that's far more understandable than what Ive been - incredibly helpful and thank-you for taking the time.

Having the doors open when in range is one possible option - i was also considering having a ship system to toggle them open/closed.

So I assume the next steps are to:
1. Have the door sprites individually drawn up and numbered 00 - 01 - 02 - ect.
2. Have your code below in a .java file in the scripts folder
3. Have the .wpn file "everyFrameEffect" referencing "openDoors"

1. Yeah. you can look at the ACG as a reference to how the sprites should be named.
2. Yep ( I think? I have all my scripts in a .jar, but im pretty sure loose scripts work?)
3. Yep

you will need to make a few changes to the script like having the proper imported classes and probably a few other things (for example, 'enemiesInRange' could be ShipAPI.areAnyEnemiesInRange())
Logged