I've been working on a cframe bullet drop script, where it creates a ray every so often based on raysPerSecond and metersPerSecond (basically studs per second.) The issue is that when i increase the raysPerSecond, the "bullet" drops a lot faster than a lower raysPerSecond. When the raysPerSecond is set to 6, it gives me roughly the right travel time to bullet drop, but when I increase it, it drops a lot more compared to its travel time. Here's the script:
local plr = game.Players.LocalPlayer;
local char = plr.Character;
local m = plr:GetMouse()
local metersPerSecond = 500;
local raysPerSecond = 30;
local dropPerSecond = Vector3.new(0, -30, 0)
local maximumDistance = 1000;
function fire()
local metersPerRay = metersPerSecond/raysPerSecond;
local raysGenerated = 0;
local function generateRay(startPosition, direction)
raysGenerated = raysGenerated + 1;
local bulletPath = Ray.new(startPosition, direction*metersPerRay)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(bulletPath, {char})
if hit ~= nil then
else
wait(1/raysPerSecond)
if raysGenerated < maximumDistance/(metersPerSecond/raysPerSecond) then
generateRay(position, ((position-startPosition)+(dropPerSecond/(raysPerSecond))).unit)
end
end
end
generateRay(char.Head.CFrame.p, (m.Hit.p-char.Head.CFrame.p).unit)
end
m.Button1Down:connect(function() fire() end)

8 comments
This was my basic understanding without looking at it too hard. The problem might also occur just because you're dividing with it, which means you'll get a smaller value wherever it is used as you increase raysPerSecond.
when i divide the drop by the raysPerSecond, this is supposed to combat that. If i keep it a constant number, it will just speed up the bullet and the drop will be less when i lower raysPerSecond.
I've condensed ythe code to the bare minimum, hope this makes it easier to understand, sorry
That would solve the problem entirely, but I am thinking of doing a setting for minimal lag where the bullet's tracers will be a bit more blocky (lower raysPerSecond.) I've tested it, and a raysPerSecond of 12 has twice the bullet drop of a raysPerSecond of 6, so there has to be some equation to make sure they both have the same amount of bullet drop. The problem is most likely in line 22, as that
Also, the time it takes to travel without bullet drop is the same throughout any raysPerSecond.
fixed it, had to take the bullet drop and divide it by raysPerSecond squared, rather than just raysPerSecond. Thanks
You'd have to change something in the part that calculates the drop using metersPerRay, maybe by using an exponential function of some sort. Keep in mind that the less frequently you cast the rays, the less accurate the drop wil be.
At First I thought it was the accuracy of the ray's drops, but sometimes it would go 10 times the normal bullet drop. I did " generateRay(position, ((position-startPosition)+((dropPerSecond*2)/(raysPerSecond^2))).unit)" for line 22 and it worked.