Jump to content

Custom projectile won't destroy itself after impact


Recommended Posts

That's the weird thing, it's already there.

local function onhit(inst, attacker, target)
    local impactfx = SpawnPrefab("impact")
    if impactfx ~= nil then
        local follower = impactfx.entity:AddFollower()
        follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0)
        if attacker ~= nil then
            impactfx:FacePoint(attacker.Transform:GetWorldPosition())
        end
    end
    inst:Remove()
end

Should I put the mod here to get a better look at it? I've already done everything but this.

Link to comment
Share on other sites

It seems you want to spawn a impact fx on the thing you hit, yes? Maybe this code will work better, hopefully  :).

Spoiler

local impact = SpawnPrefab("impact")
local x, y, z = inst.Transform:GetWorldPosition()
local x1, y1, z1 = target.Transform:GetWorldPosition()
local angle = -math.atan2(z1 - z, x1 - x)
impact.Transform:SetPosition(x1, y1, z1)
impact.Transform:SetRotation(angle * RADIANS)
impact.Transform:SetScale(2, 2, 2)

 

 

EDIT: Also, did you try putting "impactfx:Remove()" instead of "inst:Remove()"?

Edited by SuperDavid
Link to comment
Share on other sites

Oh wait, you want your item do despawn when it hits something? Well, I dunno much about how items work & stuff, but try this out, maaaybe it might work..

cactusspine.lua

If it still doesn't work, maybe giving it finiteuses component then breaking it after it hits its target will remove it?

Link to comment
Share on other sites

1 hour ago, SuperDavid said:

Oh wait, you want your item do despawn when it hits something? Well, I dunno much about how items work & stuff, but try this out, maaaybe it might work..

cactusspine.lua

If it still doesn't work, maybe giving it finiteuses component then breaking it after it hits its target will remove it?

That did it! That was the one thing that was keeping me from uploading it to the Steam Workshop! Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...