Math for fixed bullet spread and exploiter prevention

Hello, I’m making a shotgun and I have a few questions:

1) What’s the math for generating a fixed bullet spread pattern?
I’ve looked around the forum to find this, but I’ve so far found only random spread functions (I’m also completely helpless with making CFrames work). What I want is for the bullets to fan out in a fixed pattern like this (from TF2):

2) How do I prevent exploiters from removing spread? Is it even worth trying to do this?
I’ve tried server-side raycasting, and it completely destroys the client’s experience, so I’ve been doing hit detection client-side and using the server to verify the hit detection, deal damage, etc. However, for weapons like shotguns, an exploiter could remove the bullet spread and fire all the raycasts perfectly accurately.

2 Likes

Create a CFrame that is looking in the direction the player is firing by using CFrame.lookAt() and then in a loop like this

for i = 1, 8 do

rotate it by a CFrame rotated on the Z axis by math.pi * 2 * i / 8 which is also rotated by a CFrame that’s rotated on the y axis depending on how much you want it to spread

Here’s the whole code for it

cframeDirection = CFrame.lookAt(Vector3.zero, fireDirection)
spread = 0.01

for i = 1, 8 do
	cframeSpreadDirection = cframeDirection * CFrame.fromOrientation(0, 0, math.pi * 2 * i / 8) * CFrame.fromOrientation(0, spread, 0)
	spreadDirection = cframeSpreadDirection.LookVector
end

Since this is a fixed bullet spread pattern
I think you can verify the other hits based on one of the hits since the spread pattern is always the same and there is no way somebody could fire them with any different pattern unless they’re exploiting

1 Like

Thank you so much for answering the first question. I’m still stumped on how to reliably verify that the client is raycasting correctly.

I guess the client could send the server a table containing the raycast result data, but they could always spoof it so that the information followed the bullet spread.

1 Like

You could do a compromise between server and client raycasting. This should allow for some tolerance with laggy players or unfortunately exploiters at the same time.

Not exactly sure how this would work with shotun spread, probably would only need to check with 1 center bullet and the rest are relative to it.

Hello, sorry for the exceedingly late reply.

The bullets are instant raycasts and are not dependent on any projectile motion. I’m just going to forget about the server-side checks for now and focus on making other things in my game work.

Thank you for the replies, everyone.

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