How do I set the life of a particle?

  • Humanperson
    22nd January Member 0 Permalink

    when I try setting the life of an energy particle it just dies rather then working, my goal is to make it work like neutrons where you spawn it and it slowly loses life and then dies.

     

    my current code:

     

    local PION = elements.allocate("PARTICLES", "PION")

    elements.element(elements.PARTICLES_PT_PION, elements.element(elements.DEFAULT_PT_NEUT))
    elements.property(elements.PARTICLES_PT_PION, "Name", "PION")
    elements.property(elements.PARTICLES_PT_PION, "Description", "Pions, mesons made of up and down quarks, with one normal and one anti-quark.")
    elements.property(elements.PARTICLES_PT_PION, "Colour", 0xeeee22)
    elements.property(elements.PARTICLES_PT_PION, "MenuSection", 10)
    elements.property(elements.PARTICLES_PT_PION, "Gravity", 0)
    elements.property(elements.PARTICLES_PT_PION, "Flammable", 0)
    elements.property(elements.PARTICLES_PT_PION, "Temperature", 290)
    elements.property(elements.PARTICLES_PT_PION, "Explosive", 0)
    elements.property(elements.PARTICLES_PT_PION, "Weight", -1)

    pionUpdate = function(i, x, y)

        local clife = 600
        tpt.set_property('life', clife, i)
        if clife == 600 then
            velAngle = math.deg(math.random(360))
            tpt.set_property('vx', (math.sin(velAngle)*-2), i)
            tpt.set_property('vy', (math.cos(velAngle)*2), i)
        end
        clife = clife - 1
        if clife < 600 then
            tpt.set_property('type', 0, i)
        else
            tpt.set_property('life', clife, i)
        end
    end

    elements.property(elements.PARTICLES_PT_PION, "Update", pionUpdate)
  • Tadpole1
    22nd January Member 1 Permalink

    elements.property(elements.PARTICLES_PT_PION, "Properties",elements.TYPE_ENERGY+elements.PROP_LIFE_KILL_DEC)

  • Humanperson
    22nd January Member 0 Permalink

    @Tadpole1 (View Post)

     I tried adding that and it didn't work

  • Alchnoious
    22nd January Member 0 Permalink

    You can handle it like this:

     

    local pion = elements.allocate("PARTICLES", "PION")

     

    elements.element(pion, elements.element(elements.DEFAULT_PT_NEUT))

    elements.property(pion, "Name", "PION")

    elements.property(pion, "Description", "Pions, mesons made of up and down quarks, with one normal and one anti-quark.")

    elements.property(pion, "Colour", 0xFFEEEE22)

    elements.property(pion, "MenuSection", elem.SC_NUCLEAR)

    elements.property(pion, "Properties", elem.TYPE_ENERGY + elem.PROP_LIFE_DEC + elem.PROP_RADIOACTIVE + elem.PROP_LIFE_KILL

     + elem.PROP_PHOTPASS)

    elements.property(pion, "Temperature", 290)

    elements.property(pion, "DefaultProperties",{["life"]=600})

     

     

    local function pionUpdate(i,x,y,s,n)

        local itmp = sim.partProperty(i, "tmp")

        if itmp ~= 1 then

            local theta = math.rad(math.random(0,359))

            sim.partProperty(i, "vx", math.sin(theta)*3)

            sim.partProperty(i, "vy", math.cos(theta)*3)

            sim.partProperty(i, "tmp", 1)

        end

    end

     

    elements.property(pion, "Update", pionUpdate)

    Edited once by Alchnoious. Last: 22nd January