Help with lead shot

So, I got a fire wizard that shoots fireballs slow. I want the fire wizard to have accurate aim when shooting an NPC that is moving.

local caster = FastCast.new()
	FastCast.VisualizeCasts = ToolData.DebugMode
	
	local castBehavior = FastCast.newBehavior()
	castBehavior.RaycastParams = castParams
	castBehavior.Acceleration = Vector3.new(0, ToolData.EffectGravity, 0)
	castBehavior.AutoIgnoreContainer = false
	castBehavior.CosmeticBulletContainer = projectilesFolder
	castBehavior.CosmeticBulletTemplate = ToolData.Projectile

	castParams.FilterDescendantsInstances = {tool.Parent, projectilesFolder}
	
	caster.LengthChanged:Connect(function(cast, lastPoint, direction, length, velocity, projectile)
		if projectile then
			local projectileLength = (projectile.Size.Z/2)
			local offset = CFrame.new(0, 0, -(length - projectileLength))
			projectile.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
		end
	end)

	caster.RayHit:Connect(function(cast, result, velocity, projectile)

	end)

	local orgin = firePoint.WorldPosition
	local direction = (hitPosition - orgin).Unit
	caster:Fire(orgin, direction, ToolData.BulletSpeed, castBehavior)

no idea how your code works. but here is how you can do it :

  • predict the next position of the npc. here is the code
local npcChar = --replace this with your npc character
local npcRoot = npcChar.HumanoidRootPart
local fireWizard = --replace this with firewizard part

local shootSpeed = --fireball speed in studs
local shootTime = (fireWizard.Position - npcRoot.Position).Magnitude / shootSpeed

local nextPosition = npcRoot.Position + (npcRoot.Velocity * shootTime)
  • aim and shoot the fireball to nextPosition

i have bad english so i hope you understand what im saying

How would I attach this to CFrame.LookVector?

local shootTime = (character.PrimaryPart.Position - targetRoot.Position).Magnitude / toolData.BulletSpeed
				local nextPosition = targetRoot.Position + (targetRoot.Velocity * shootTime)
				character:PivotTo(CFrame.lookAt(character.PrimaryPart.Position, targetRoot.Position * Vector3.new(1, 0, 1) + targetRoot.Position * Vector3.new(0, 1, 0)))
1 Like

I tried this

local shootTime = (character.PrimaryPart.Position - targetRoot.Position).Magnitude / toolData.BulletSpeed
				local nextPosition = targetRoot.Position + (targetRoot.Velocity * shootTime)
				character:PivotTo(CFrame.lookAt(character.PrimaryPart.Position, nextPosition * Vector3.new(1, 0, 1) + nextPosition * Vector3.new(0, 1, 0)))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.