Modding Help Particle tag "variants" and how to use it

Discussion in 'Starbound Modding' started by EmissaryOfInfinity, Jan 20, 2017.

  1. EmissaryOfInfinity

    EmissaryOfInfinity Subatomic Cosmonaut

    So I noticed in my time working with particles that there's a tag in most of the .animation files labelled "variants," yet in every animation in the base game I've looked at, it's set to 1. Does anyone have any clue how you would use it if it were set to a higher number? There's no documentation on this feature that I've been able to find, and my hope is that the end result is particles spawning with a randomly selected image from a specified pool. This is vital to a certain feature of a mod I'm working on, so I'd love to have some help here.
     
  2. bk3k

    bk3k Oxygen Tank

    I'm pretty sure it would work just like tile variants do. So yes it need not have identical animation each time, but could have a few to choose from.
     
  3. EmissaryOfInfinity

    EmissaryOfInfinity Subatomic Cosmonaut

    I intend to try a bit more experimentation when I get home from work tomorrow, so maybe I'll make a breakthrough. As it stands, though, the formatting for it remains quite opaque - the only place it's used in Vanilla is the muzzle flash for basic guns, and that's so hacked-together that it doesn't even have all the necessary files for an animated particle. My best attempt at use earlier resulted in a particle that worked, but would only spawn the first frame of the first type. I'll have to explore why this is later...
     
  4. bk3k

    bk3k Oxygen Tank

    With those examples(also plasmamuzzle1), I'll tell you exactly how it works.
    Code:
    {
      "frames" : "plasmamuzzle1.png",
      "variants" : 2,
      "frameNumber" : 4,
      "animationCycle" : 0.03,
      "offset" : [0.375, 0]
    }
    frameNumber tells it how many frames per animation. 4 frames per animation with 2 variants means 8 frames.
    Put your frames horizontally. The frames for your first variant, the frames for the second variant.
    Then the frames file
    Code:
    {
      "frameGrid" : {
        "size" : [15, 15],
        "dimensions" : [8, 1]
      }
    }
    size tells it the size of the frames in this case 15 pixels[x] by 15 pixels[y].
    dimensions tells it your image has 8 frames arranged horizontally
    I think in this case they could have done
    "dimensions" : [4, 2]
    and put the variants below one another to still get the same 8 frames but more visibly separate the variants as is generally done with color variant separation. File that under purely optional but probably desirable if you have many variants.
     
  5. EmissaryOfInfinity

    EmissaryOfInfinity Subatomic Cosmonaut

    That was my first thought, too. Problem is, that's what I tried that wound up resulting in the lock-up on the first variant. I was quite tired and frustrated at the time, so I wouldn't put it past me to have made a silly mistake, but so far as I can tell a basic "copy what they did" isn't gonna work here. Hopefully it turns out we were right, and that's all that need done, because it'd vastly simplify things later.
     
  6. bk3k

    bk3k Oxygen Tank

    Copying what they did SHOULD work. Possibly you did something minor that means the frames file doesn't match up to the actual image. It is possible(even if unlikely) that you would be stuck with all your images horizontal like they do.
     
  7. EmissaryOfInfinity

    EmissaryOfInfinity Subatomic Cosmonaut

    So...some interesting results here.
    For starters, copying just those two files results in an Ordered Map error when the particle is called, which seems reasonable given the normal mechanics of particles. Adding in the necessary lines in the .animation file for my tech, and creating the effectsource and particle files yields yet weirder results than the first time. While the particles do spawn, and the game recognizes they should have some variation, it doesn't seem to understand that said variation should be dynamic. It chooses a single variant each time the game is started, and loads that same variant every time the particle is called in that session. Mind, the particle image is formatted horizontally, so that wouldn't be an issue. I also attempted adding in the math.random function that gunfire.lua uses to set its randomness, but it made no difference. And stranger still, it spawns a static version of said particle on top of the player while active, always using the first frame of the first variant. I'm stumped as to why all of this is. I'll paste the code from my files below, in case anyone else can give any insight...

    From vartest.animation:
    Code:
    {
      "frames" : "vartest.png",
      "variants" : 3,
      "frameNumber" : 2,
      "animationCycle" : 2.0,
      "offset" : [0.0, 0.0]
    }
    


    From vartest.frames:
    Code:
    {
      "frameGrid" : {
        "size" : [30, 30],
        "dimensions" : [6, 1]
      }
    }
    


    From vartest.effectsource:
    Code:
    {
      "kind" : "vartest",
      "definition" : {
        "duration" : 0.01,
        "loops" : false,
        "location" : "normal",
        "start" : {
          "particles" : [
            [ ]
          ],
          "sounds" : [
            [ ]
          ]
        },
        "particles" : [
          [ "vartest" ]
        ],
        "sounds" : [
          [ ]
        ],
        "stop" : {
          "particles" : [
            [ ]
          ],
          "sounds" : [
            [ ]
          ]
        }
      }
    }
    


    From vartest.particle:
    Code:
    {
      "kind" : "vartest",
      "definition" : {
        "type" : "animated",
        "animation" : "/animations/vartest/vartest.animation",
        "position" : [0, 0],
        "finalVelocity" : [0, 0],
        "approach" : [0, 0],
        "size" : 1,
        "layer" : "middle",
        "timeToLive" : 2.0,
        "variance" : {
        }
      }
    }
    


    Both calling it as a burst and normal particle emitter result in the same thing, so it's clearly not that...
     
  8. EmissaryOfInfinity

    EmissaryOfInfinity Subatomic Cosmonaut

    Alright, I've tried everything I could, saw some new info that proved fruitless, and still gotten nothing to work as it appears it should. From what I can tell, the only reason the muzzle flash works as it does it because it's not actually a particle, but an animated part of the item, and the particles we saw were completely unused, outdated artifacts of old builds. While this could potentially be manipulated for other projects, it's not useful for what this thread was dedicated to - actual particles with random variants. So if anyone in the future ever figures out how to do it, please, please post your findings here. It would be phenomenal to finally figure this out and be able to move on.
     
  9. olsonpm

    olsonpm Void-Bound Voyager

    Just ran into this and spent 3-4 hours trying to figure out how to get variants to work with no luck. It's a bummer so much functionality either doesn't work as the code suggests it might, or is hidden otherwise by the underlying engine.
     

Share This Page