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

How do a put a the mouse position in the center of the chosen part?

Asked by 6 years ago

I'm making another placement system but now i have the problem that the mouse isn't in in the middle of the part it's really buggy cause the mouse isnt in the middle i have a part that is in the middle and i want the mouse to focus on that part while moving the chosen part but it ain't focusing on anything except the chosen part you are moving around. So how do i put the mouse in the middle part when i'm moving the part?

heres the local script:

local grid = 8
game:GetService("RunService").RenderStepped:connect(function()
    mouse.TargetFilter = moveItem
    local X,Y,Z = (moveItem.Hitbox.Size.Z/2)%1, moveItem.Hitbox.Size.Y/2, (moveItem.Hitbox.Size.X/2)%1
    local p = CFrame.new(Vector3.new( (mouse.Hit.x+(grid/2)) - (mouse.Hit.x+(grid/2))%grid, mouse.Hit.y, (mouse.Hit.z+(grid/2)) - (mouse.Hit.z+(grid/2))%grid, camera.CFrame.p))*CFrame.new(0,1,-0).p

    moveItem:SetPrimaryPartCFrame(CFrame.new(math.floor(p.X)+X,math.floor(p.Y+Y),math.floor(p.Z)+Z))


end)

Answer this question