Movement handles moving in the wrong direction

  1. What do you want to achieve?
    I want to make the movement handles move on the right direction

  2. What is the issue?
    I made a part movement system using movement handles, however, the handle moves the part in the wrong direction. It seems like it only works right for parts with the 0,0,0 orientation. Also for each orientation the handle changes its direction

Here’s the script:
(it’s a local script placed into a ScreenGui in the StarterGui, inside there’s also a ObjectValue named “Part” which I used for testing. Also the parts need to have a BoolValue inside called “CanMove” for them to work with the system)

local plr = game.Players.LocalPlayer
local m = plr:GetMouse()

m.Button1Down:Connect(function()

	if m.Target:FindFirstChild("CanMove") then  ----- can only use parts with a boolvalue inside called "CanMove"
		script.Parent.Part.Value = m.Target
		
		if script.Parent:FindFirstChild("handle") then
			script.Parent.handle:Destroy()
		end
		
		
			local handle = Instance.new("Handles")
			handle.Parent = script.Parent
			handle.Style = "Movement"
			handle.Name = "handle"
			handle.Adornee = m.Target 
			
			local lastCFrame = nil

			script.Parent.handle.MouseDrag:Connect(function(face,distance)
				local Direction = Vector3.FromNormalId(face)
				script.Parent.Part.Value.CFrame = lastCFrame + (Direction * distance)
			end)

			script.Parent.handle.MouseButton1Down:Connect(function()
				lastCFrame = script.Parent.Part.Value.CFrame
			end)
		end
end)

It’s probably that the vector you get is in world space. So, you would need to convert it into local space by using :VectorToWorldSpace which gives you the chosen direction relative to the part, since it will change depending on its orientation.

local Direction = script.Parent.Part.Value.CFrame:VectorToWorldSpace(Vector3.FromNormalId(face))

edit: The right one is :VectorToWorldSpace, not object space, I always mix them up

1 Like

I didn’t realize I was using the world space vector. It works now. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.