Need help with a Boss NPC

So I basically made an NPC that ‘imitates player’ but this keeps happening:

Before we continue, NO I did not add pathfind to the NPC. (It’s very laggy if I do it specifically to him) He basically stopped at a certain distance THEN attacks, and I want to force players to use covers for this ‘Boss fight’

Is there a solution to this problem?

5 Likes

You could use raycast so he only shoots when he sees the character.

1 Like

ok, that’s smart. But another problem is how would I get him to look for the player?

1 Like

You mean like so he goes to the player or him be able to see the player?

1 Like

he goes to the player, then shoots them.

1 Like

I think you do need PathfindingService for this. (yes i read the thing that he lags when you use it)

1 Like

Could you also use raycatsing to make sure that it has a line of sight to the player before attacking?

1 Like

Here is an example of what I mean from one of my games:

local function canSeeTarget(target)
	local origin = boss.HumanoidRootPart.Position
	local direction = (target.HumanoidRootPart.Position - boss.HumanoidRootPart.Position).unit * 40
	local ray = Ray.new(origin, direction)

	local hit, pos = workspace:FindPartOnRay(ray, boss)


	if hit then
		if hit:IsDescendantOf(target) then
			return true
		end
	else
		return false
	end
end

Edit: you need to have a boss variable for the model of the npc

1 Like

ok. I know how to do that. But how would you make it so that he moves around the corner and find the player. This is mainly about the npc finding his way to the player.

2 Likes

Yes, that is pathfining service. You need to calculate a path around obstacles from point 1 (the boss’s position) to point 2 (the player’s)

2 Likes

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