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
Can't you just find the distance between each of the parts? For example:
local distance = (Part1.Position - Part2.Position).Magnitude
or are you need the raycast for something a little more complex?