Boss with gun aiming

So I got the basis of this down my problem is that I want the boss to shoot to you and then past and behind you, I can’t just use a blahblah.CFrame*CFrame.new(25,0,0) (sorry I forgot how to do the block of code thing) because then depending on the characters angle It’ll just shoot to the side of them. The problem with just shooting to the character’s coords is that you can just walk backwards to avoid the bullets (video)

local bullet = game.ReplicatedStorage.StoredModels.Bullet:Clone()
			bullet.Parent = chr.Parent
			bullet.CFrame = chr["Right Arm"].CFrame
			local move = TS:Create(bullet, TweenInfo.new(.25, Enum.EasingStyle.Linear), {CFrame = chr.Target.Value.Parent.HumanoidRootPart.CFrame})
			move:Play()

Nevermind I think I’ve found a solution and will just post it here for anyone who wants to know.

Ok, so I made a few small changes to my original script

	local bullet = game.ReplicatedStorage.StoredModels.Bullet:Clone()
			bullet.Parent = chr.Parent
			bullet.CFrame = chr["Right Arm"].CFrame
			bullet.Orientation = chr.HumanoidRootPart.Orientation
			local move = TS:Create(bullet, TweenInfo.new(.25, Enum.EasingStyle.Linear), {Position = chr.Target.Value.Parent.HumanoidRootPart.Position})
			move:Play()
			wait(.125)
			move.Completed:Connect(function()
				local move2 = TS:Create(bullet, TweenInfo.new(.5, Enum.EasingStyle.Linear), {CFrame = bullet.CFrame*CFrame.new(0,0,-50)})
				move2:Play()
			end)

The key to this working is that the npc is always facing your character, this is most easily achieved by using CFrame.LookAt(npc pos, ur chr pos) I used this really simple repeat to do that

script.Parent.Walking.Changed:Connect(function(val)
	if val == true then
		repeat
			wait()
			chr:SetPrimaryPartCFrame(CFrame.lookAt(chr.HumanoidRootPart.Position, chr.Target.Value.Parent.HumanoidRootPart.Position))
		until
		script.Parent.Walking.Value == false
	end
end)

(Walking in that script is basically just a value to check if the boss is locked onto something)
I’d just take a distance tracking script to figure out your locking on and such.
And that’s all it took.
If you want to make the speed of the bullet more consistent use the plr:DistanceFromCharacter and do some division from there to get a constant speed for every shot, for me it’s not all that important so I’m just ignoring it.

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