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

How do I position and rotate a part so it aligns properly with a parts normal and rotation?

Asked by 8 years ago
Edited 8 years ago

I am attempting to recreate the Roblox Dragger class as it is incompatible with FilteringEnabled. I am far from decent when it comes to 3D mathematics and CFraming. I have mustered up this piece of code:

local MouseRay = Ray.new( Mouse.UnitRay.Origin, Mouse.UnitRay.Direction * 999 )
local IgnoreList = { Player.Character, DragPart }
local Hit, Position, Normal = workspace:FindPartOnRayWithIgnoreList( MouseRay, IgnoreList )

--local Position = Vector3.new( math.floor( Position.x ), math.floor( Position.y ), math.floor( Position.z ) )

local Shifted = Hit.CFrame + ( ( DragPart.Size/2 ) * Normal )
local MousePosition = Hit.CFrame:toObjectSpace( CFrame.new( Position ) ):inverse()
Shifted = Shifted - MousePosition.p

DragPart.CFrame = Shifted

It works in a very mediocre fashion for only a single part and completely falters once any rotation is applied to the moused over part.

The main question is - How do I align the part I am moving with the 'grid' of the part I am moused over? This is all to achieve the goal of moving a part along the grid in 1 stud increments much like the 'Dragger' class.

Thanks in advance for any provided help.

0
I don't see a reason why dragger wouldn't work with FE. It will obviously have to be made my client, since it's completely local feature. Then on resizing you would need to send the new size to server ZarsBranchkin 885 — 8y
0
I have done extensive testing on the dragger for both local and serverside. The short conclusion is that locally doesn't function consistently and the serverside is a mess of remotevent spamming and lag SirHorse 0 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

I'm no expert when it comes to 3D mathematics (I'm on a steady learning pace) but if I'm not mistaken you may have to manually snap the part to a predetermined position along with use of math.ceil(x)because it will round a number up to it's nearest whole, and math.floor(x) will round it down to it's nearest whole.

(Also if you want to automatically round up or down depending on the decimal, then you could write a rounding function.)

function numberRound(number)
local High = math.ceil(number) - number
local Low = number - math.floor(number)
if High > Low then
return High
elseif High < Low then
return Low
end
end

Now like I said, I'm not entirely sure if this is correct but I hope this at least reveals any possibilities to fixing your problem (if it doesn't already)

0
You're entirely correct about rounding and the commented out section of my code snippet is a decent attempt at just that. It's basic but works when it is applied to the world grid system. The problem lays in the fact that once a part has been rotated and the position is displaced in to a small unit place the whole system fails. Parts particularly won't align to the bricks rotation and corners SirHorse 0 — 8y
Ad

Answer this question