Jump to content

Issue with Projectile component


Recommended Posts

Hey all, so I am working on a book for Wickerbottom that harvests tree's. The idea is to have the tree fall down that obviously spawns the log prefabs and then have them get sucked to the readers position.  The problem that I have is that if the reader moves the logs will just continue to follow forever and ever.  The intended behavior would be to give the projectile:Throw a target location and not an actual target.  I have taken a look at the complexprojectile component but it has some strange behavior with gravity and doesn't always make it to the target location.  Here is the code that I have for the book so far.  I appreciate any help.

Spoiler

--For debugging tables.
function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

local assets =
{
    Asset("ANIM", "anim/book_lumberjack.zip"),
	Asset("ATLAS", "images/inventoryimages/book_lumberjack.xml"),
    Asset("IMAGE", "images/inventoryimages/book_lumberjack.tex"),
}

local function OnHit(inst, attacker, target)
    
    inst:Remove()
end

local function OnMiss(inst, attacker, target)
	print("you missed")
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("book_lumberjack")
    inst.AnimState:SetBuild("book_lumberjack")
    inst.AnimState:PlayAnimation("idle")
	

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	-----------------------------------
	
	inst:AddComponent("inspectable")
	inst:AddComponent("book")
	
	inst.components.book.onread = function(inst, reader)
	
	local me = reader
	local x,y,z = me.Transform:GetWorldPosition()
	local trees = TheSim:FindEntities(x,y,z,10,{"tree"},nil,nil)
	
	for k,v in pairs(trees) do
		v.components.workable:WorkedBy(me, v.components.workable.workleft)
	end
	
	local logs = TheSim:FindEntities(x,y,z,15,nil,nil,nil)
	
	for k, v in pairs(logs) do
		if v.prefab == "log" then			
			v:AddComponent("projectile")
		    v:AddComponent("weapon")
			v.components.weapon:SetDamage(0)
			v.components.projectile:SetSpeed(5)			
			v.components.projectile:Throw(v,me)			
		end
	end

		reader.components.sanity:DoDelta(TUNING.SANITY_BOOK)			
		return true
	end

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "book_lumberjack"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/book_lumberjack.xml"

	inst:AddComponent("finiteuses")
	inst.components.finiteuses:SetMaxUses(TUNING.USES_BOOK)
	inst.components.finiteuses:SetUses(TUNING.USES_BOOK)
	inst.components.finiteuses:SetOnFinished(inst.Remove)

	inst:AddComponent("fuel")
	inst.components.fuel.fuelvalue = TUNING.MED_FUEL

	MakeSmallBurnable(inst, TUNING.MED_BURNTIME)
	MakeSmallPropagator(inst)

	MakeHauntableLaunch(inst)

	return inst
end

return  Prefab("book_lumberjack", fn, assets, prefabs)

 

 

Edited by Silisiban
Link to comment
Share on other sites

TBH m8, I think it would be simpler to just make your own component, which makes the object move towards a certain point, instead of a certain target. Buuut, since you can change the projectile component for just your prefab in any way you want, you might be able to swing it by creating a new function in the projectile component, which does what you want. I'd have to study the projectile component more to see what's possible. I'll hit you back on Steam when I've taken a look.

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...