Im trying to make a anti air system, and for the gameplay the bullets are intentionally slow. To track the client-sided bullets I’m using raycasts, however I am very tired and very inexperienced with using raycasts, so this simple concept is clogging my foggy head.
My raycasts currently get longer over time, and don’t actually progress with the bullet (image reference if it helps below, what I have is A. and what I want is B)
For anyone curious, this is my current code for the raycasting
for index = 0, max_range, (max_range / bullet_checks) do
raycast_direction = raycast_origin.CFrame.LookVector * -index --increases raycast size
raycast_result = workspace:Raycast(raycast_origin.Position, raycast_direction)
if (raycast_result ~= nil) then
raycast_distance += raycast_result.Distance --Adds distance of contact onto other raycasts
break
elseif(index == max_range) then
raycast_distance = nil --Distance not allocated within bullet's range
break
end
raycast_distance += index --Since no object was found on this RC, it adds the index to the sum
task.wait((max_range / bullet_checks) / round_SPS) --Wait until new Raycast
end