i have a moving car that has a part at the back. it detects the part behind it and then prints out the distance between both. but its really inconsistent. for example, when i get closer to a part, its at 14 or something and when you get closer it reduces to about 13 (another question, why isnt it just 0?), but when i try to get away and then get close again, its something like 11 and then reduces to 10, which makes no sense at all.
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult =
game.Workspace:Raycast(rayOrigin,car.Body.Cameras.RayCam.CFrame.LookVector*-4, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
hh = (rayOrigin - hitPart.Position).magnitude
end

1 comment
No, what they are trying to do is see which part is behind the car, then calculate the distance. The raycast is necessary to find that.