Script.movespeed=30
Script.pickradius=0
Script.damage=50
Script.lifetime=300000
Script.enabled=true
Script.inheritance=Vec3(0,0,0)
function Script:Start()
	self.sound={}	
	self.sound.ricochet={}
	self.sound.ricochet[3]=Sound:Load("Sound/Ricochet/bullet_impact_dirt_03.wav")
	self.starttime=Time:GetCurrent()
	self.prevPos=self.entity.position
end

function Script:FindScriptedParent(entity,func)
	while entity~=nil do
		if entity.script then
			if type(entity.script[func])=="function" then
				return entity
			end
		end
		entity = entity:GetParent()
	end
	return nil
end

function Script:UpdateWorld()
	if self.enabled==false then return end
	if self.entity:Hidden() then return end
	local pickinfo=PickInfo()	
	local pos = self.entity:GetPosition(true)
	local targetpos = Transform:Point(0,0,self.movespeed * Time:GetSpeed(),self.entity,nil)
	targetpos = targetpos + self.inheritance * Time:GetSpeed()
	local result = self.entity.world:Pick(pos,targetpos,pickinfo,self.pickradius,true,Collision.Projectile)
	if result then
		self:Explode()
	else
		self.entity:SetPosition(targetpos)
	end
	if Time:GetCurrent()-self.starttime>self.lifetime then
		self.entity:Release()
	end
	self.prevPos=self.entity.position
end


function Script:Explode()
	local expl = Prefab:Load("prefabs/explosion.pfb")
	expl:SetPosition(self.entity:GetPosition(true))
	expl:EmitSound(self.sound.ricochet[3])

	self.entity:Release()
end




--