I am making a weapon that fires projectiles, and I want the projectiles to hover above ground like blowdarts, but when I fire my projectiles - they simple slide along the ground. How do I achieve the flying effect that blowdarts have?
Something I considered is setting the Y of the projectile to something like 1.5, but then it won't collide properly with the target, since everything has a Y of 0, and gravity would affect the projectile. Here is my current code:
local assets={
Asset("ANIM", "anim/rpgprojectile.zip"),
}
prefabs = {}
local function onthrown(inst, data)
inst.AnimState:SetOrientation(ANIM_ORIENTATION.OnGround)
inst.AnimState:PlayAnimation("idle")
local x,y,z = inst.Transform:GetWorldPosition()
inst.Transform:SetPosition(x,1.5,z)
end
local function fn()
local inst = CreateEntity()
local trans = inst.entity:AddTransform()
local anim = inst.entity:AddAnimState()
inst.entity:AddNetwork()
MakeInventoryPhysics(inst)
inst.AnimState:SetBank("rpgprojectile")
inst.AnimState:SetBuild("rpgprojectile")
inst.AnimState:PlayAnimation("idle")
MakeInventoryPhysics(inst)
RemovePhysicsColliders(inst)
if not TheWorld.ismastersim then
return inst
end
inst:AddComponent("projectile")
inst.components.projectile:SetSpeed(30)
inst:ListenForEvent("onthrown", onthrown)
inst.components.projectile:SetOnHitFn(inst.Remove)
inst.components.projectile:SetOnMissFn(inst.Remove)
inst:AddComponent("explosive")
inst:AddTag("NOCLICK")
return inst
end
return Prefab("rpgprojectile", fn, assets, prefabs)