I was starting to make good progress on my new game but I couldn’t really get how why this isn’t working.
Here is the code,
function moveCar(Part:BasePart,Goal:Vector3)
local Hit = MS.Hit.Position
local Delta = Vector3.new(Hit.X,0,Hit.Z) - Vector3.new(lastPos.X,0,lastPos.Z)
local Offset = Part.CFrame.LookVector * Vector3.new(Delta.X,0,Delta.Z)
Part.Position += Offset
end
if DraggedPart then
MS.TargetFilter = Level
moveCar(DraggedPart,MS.Hit.Position)
MS.TargetFilter = nil
end
(Note: I got this from a js code, and edited it, so it might have some syntax issues, also the Position and Size and x and y values might be mixed up.)
Edit: I just wanted to add, that if we use a variable that is a bool (I’ll call it CanUpdate), and a variable that is a Vector3 (I’ll call it PreviousPos). Then we can edit your code:
local CanUpdate = true
--local PreviousPos = -- get the position of the car
function moveCar(Part:BasePart, Goal:Vector3)
if canUpdate then
canUpdate = false
local colliding = false
-- loop though the hitboxes and put them into the function, replace "table" with this list
in i, hitBox in ipairs(table) do
colliding = isColliding(Goal, hitBox)
if colliding then
break
end
end
if isColliding then
local Hit = MS.Hit.Position
local Delta = Vector3.new(Hit.X,0,Hit.Z) - Vector3.new(lastPos.X,0,lastPos.Z)
local Offset = Part.CFrame.LookVector * Vector3.new(Delta.X,0,Delta.Z)
Part.Position += Offset
end
end
end
(Wait I just realized PreviousPos is redundant lol.)