How to make projectiles that can hit NPCs who don't physically exist in the server?

Hello developers!

I’ve been working on a NPC system that doesn’t need a physical instance (Humanoids, Parts, etc) to improve server - client performance and handle 500+ bots. The server modifies all of the NPC’s position data 30 times a second and replicates them to clients 15 times a second. The client’s task is to render any NPC model on screen and lerp them to their goal.

A problem I realized is how I’m going to be able to detect if a server projectile hits a NPC.

I made up two methods who which are the following:
1 | Request data from the NPC handler script using a BindableFunction and a for loop as a “radius”, but this seems really expensive to compute especially if it’s running 60 times a second.

2 | Custom raycast that is adapted to the NPC handler (I don’t know how to achieve this part)

1 Like

Cast a raycast check if it hit if so get the hit instance then check what it is with OBJ:IsA("ClassName") if humanoid damage it.

Example Code:

function ShootRaycast()
	local Blacklist = {Character, workspace.Ignore}
	raycastParams.IgnoreWater = true
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = Blacklist

	local Mouse = UserInputService:GetMouseLocation()
	local unitRay = workspace.Camera:ViewportPointToRay(Mouse.X, Mouse.Y)

	local Raycast = workspace:Raycast(unitRay.Origin, unitRay.Direction * 5000, raycastParams)
	if Raycast then
		return (Raycast.Position + Raycast.Normal * 1), Raycast
	end
end

local Vector3Hit, Raycast = ShootRaycast()

if Vector3Hit then
			local p = Instance.new("Part")
			p.Size = Vector3.new(SizeCurrent, SizeCurrent, SizeCurrent)
			p.Transparency = 0
			p.Material = Enum.Material.Metal
			p.CanQuery = false
			p.CanTouch = false
			p.Color = Color3.fromHex("#b87333")
			p.CanCollide = false
			p.Position = Raycast.Position + Vector3.new(0, p.Size.Y / 2, 0)
			p.Parent = workspace.Raycast_Ignore
			p.Anchored = true
end
1 Like

I’m sorry but this isn’t what I was looking for, there’s no parts that represents an NPC on the server.
This might work if done on the client but could make up security issues.
Thank you for the help though!

To make it clear, the NPCs don’t have their own physical instances, but there’s still other parts in the workspace, right?
If so, I don’t think you need a physical instance for the NPC to check whether it’s hit or not. Just cast a ray from the projectile’s initial position to the NPC’s position and check if it hits anything or not. If it does hit something, it means something would be interfering the projectile’s trajectory and the NPC would not be hit.

The projectiles are handled within a paralleled script, there is no physical part for the projectiles on the server either. It’s basically a simulation of rays using 3D vectors.
This could be a problem if the projectiles are simulated rays instead of a instant long raycast.

You system is rather confusing to me… The projectile doesn’t have a physical part either, but it doesn’t require one to have a position, right?

Sorry for the late reply, both of them requires to have a position, like sending the bullet position to the AI handler to see if there’s any NPC near that position. Maybe doing this will be the only way to solve this