Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Distance magnitude between two parts inconsistent?

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 answer

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?

1 comment

0

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.