Modding Help How to make particles rotate with the weapon?

Discussion in 'Starbound Modding' started by PixelBlood, May 17, 2018.

  1. PixelBlood

    PixelBlood Orbital Explorer

    I've been making animated gun mods over the last two weeks, and those are working well, but now I'm also trying to make them eject spent cartridges after every shot. For this reason I've made it so that they emit a casing particle after every shot, but here's the problem: The particles flip like intended when you look the other direction, but they don't rotate with the gun, meaning that they are always stuck in the horizontal position. Of course this just looks stupid; when you aim up or down they essentially come out sideways.
    My question is: is there a way to make the particles rotate with the gun (make them come out with the same rotation the gun has the moment you shoot)?

    Here my code: akm_ej.activeitem
    Code:
    {
      "itemName" : "ak_m_ej",
      "price" : 2700,
      "inventoryIcon" : "akm_ejicon.png",
      "maxStack" : 1,
      "rarity" : "Legendary",
      "description" : "Soviet 7.62x39mm assault rifle.",
      "shortdescription" : "AK-M EJ",
      "level" : 6,
      "tooltipKind" : "gun",
      "category" : "Assault Rifle",
      "itemTags" : ["weapon","ranged","assaultrifle"],
      "twoHanded" : true,
    
      "animation" : "akm_ej.animation",
      "animationParts" : {
        "gun" : "akm_ej.png",
        "muzzleFlash" : "muzzleflash.png"
      },
     
      "animationCustom" : {
        "sounds" : {
          "fire" : [ "akmfire.ogg" ]
        }
      },
     
      "baseOffset" : [1, 0],
      "muzzleOffset" : [2.6, 0.45],
    
      "scripts" : ["/items/active/weapons/ranged/gun.lua"],
    
      "elementalType" : "physical",
    
      "primaryAbility" : {
        "scripts" : ["/items/active/weapons/ranged/gunfire.lua"],
        "class" : "GunFire",
    
        "fireTime" : 0.1,
        "baseDps" : 30,
        "energyUsage" : 75,
        "inaccuracy" : 0.02,
    
        "projectileCount" : 1,
        "fireType" : "auto",
    
        "projectileType" : "standardbullet",
        "projectileParameters" : {
          "knockback" : 8
        },
    
        "stances" : {
          "idle" : {
            "armRotation" : 0,
            "weaponRotation" : 0,
            "twoHanded" : true,
    
            "allowRotate" : true,
            "allowFlip" : true
          },
          "fire" : {
            "duration" : 0,
            "armRotation" : 3,
            "weaponRotation" : 1,
            "twoHanded" : true,
    
            "allowRotate" : true,
            "allowFlip" : true
          },
          "cooldown" : {
            "duration" : 0.09,
            "armRotation" : 1,
            "weaponRotation" : 0,
            "twoHanded" : true,
    
            "allowRotate" : true,
            "allowFlip" : true
          }
        }
      },
    
    
      "builder" : "/items/buildscripts/buildunrandweapon.lua"
    }
    
    akm_ej.animation
    Code:
    {
      "animatedParts" : {
        "stateTypes" : {
          "firing" : {
            "default" : "off",
            "states" : {
              "off" : {},
              "fire" : {
                "frames" : 9,
                "cycle" : 0.09,
                "mode" : "transition",
                "transition" : "off"
              }
            }
          }
        },
    
        "parts" : {
          "gun" : {
            "properties" : {
              "centered" : true,
              "offset" : [1, 0],
              "transformationGroups" : ["weapon"]
            },
    
            "partStates" : {
              "firing" : {
                "off" : {
                  "properties" : {
                    "image" : "<partImage>:empty"
                  }
                },
                "fire" : {
                  "properties" : {
                    "image" : "<partImage>:fire.<frame>"
                  }
                }
              }
            }
          },
          "muzzleFlash" : {
            "properties" : {
              "zLevel" : -1,
              "centered" : true,
              "offset" : [0.75, -0.1],
              "fullbright" : true,
              "transformationGroups" : ["muzzle"]
            },
    
            "partStates" : {
              "firing" : {
                "fire" : {
                  "properties" : {
                    "image" : "<partImage>:3.<frame>"
                  }
                }
              }
            }
          }
        }
      },
    
      "transformationGroups" : {
        "weapon" : {},
        "muzzle" : {}
      },
     
    "particleEmitters" : {
          "muzzleFlash" : {
            "active" : false,
            "transformationGroups" : ["muzzle"],
            "emissionRate" : 8,
            "offsetRegion" : [-2.35, 0.2, -2.35, 0.2],
            "particles" : [
              { "particle" : "shortriflecase"}
            ]
          }
        },
    
      "lights" : {
        "muzzleFlash" : {
          "active" : false,
          "position" : [0, 0],
          "color" : [90, 90, 0]
        }
      },
    
      "sounds" : {
        "fire" : ["akmfire.ogg"]
      }
    }
    
    And shortriflecase.particle (I added "rotate":true myself, but it didn't have the desired effect)

    Code:
    {
      "kind" : "shortriflecase",
      "definition" : {
        "type" : "textured",
        "image" : "/items/active/other/weapons/akm_ej/shortriflecase.png",
        "size" : 1.0,
        "fade" : 0.9,
        "initialVelocity" : [-4, 2.0],
        "finalVelocity" : [-4, -7.0],
        "approach" : [0, 20],
        "position" : [0, 0],
        "timeToLive" : 0.5,
        "layer" : "front",
        "rotate" : true,
        "collidesForeground" : true,
        "variance" : {
          "initialVelocity" : [2, 4.0]
        }
      }
    }
    
     
  2. Echo710

    Echo710 Scruffy Nerf-Herder

    There's not really a way to do that sadly. I would suggest using periodicActions to instantly fire a case projectile (projectile with grenade physics and top layer for rendering) from the fired bullet. That's really the only way to do it if you intent to have the casings rotate correctly.
     

Share This Page