Why is the node's position not at the mouse's position when its parent is moved?

I’m making a pannable node-based editor where you click on a node to move it. When the editor isn’t panned at all, there are no problems. But when you pan the editor, when you move a node, it’s position is offsetted to the mouse position. How would I fix this?

Video example:

Node Move Script (Move function just move’s the node to the position stated in the first parameter) :

local node = NodeEditor.new(NodeEditor.NodeType[v.Name])
			local moving = true

			node.UI.Button.MouseButton1Click:Connect(function()
				if moving == false then
					moving = true
				else
					moving = false
				end
			end)
			moving = true
			coroutine.wrap(function()
				while true do
					wait()
					if moving == true then
						local mouse = game.Players.LocalPlayer:GetMouse()
						node:Move(UDim2.fromOffset(mouse.X,mouse.Y))
					end
				end
			end)()

2 Likes

Does panning the node-based editor add to the scale of a nodes position?
If so then it just simply adds to offset on top of the scale which could cause this.


You could just save the scale as an offset instead and add it to the node move function like so:

node:Move(Udim2.fromOffset(mouse.X + node.X , mouse.Y + node.Y))

however this includes you needing to add X and Y to your class that changes when you pan.

Edit: It obviously would be easier to do add a NodeEditor.X to the module script and change it like:

node:Move(Udim2.fromOffset(mouse.X + NodeEditor.X , mouse.Y + NodeEditor.Y))
1 Like

No, only the editor’s position is changed

Substract the editors offset from the X and Y in the move function

node:Move(Udim2.fromOffset(mouse.X - offsetX of nodeEditor, mouse.Y - offsetY of noteEditor))

if it uses scale to move then just add the negative scale of editor instead

1 Like