Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Distance magnitude between two parts inconsistent?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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?

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. thecelestialcube 123 — 3y
Ad

Answer this question