A draggable viewport frame model, How would I do this?


I’m trying to make a viewport frame object rotate depending on where the player drags their mouse, I have absolutely no idea how to go about this.

Please, any help would be greatly appreciated, thank you!

1 Like

O boi, I spent a bunch of time working on this exact thing a while ago. There’s a surprising can of worms related to figuring out which GUI object is receiving input events. Unfortunately I don’t remember the details :I Anyway the whole thing is an interesting project. There’s a lot of little details that go into making it nice.

The very basics is detecting when a GuiObject is clicked, then locking the mouse cursor and using mouse movement to rotate either a) a model or b) a camera around a model (it matters because of lighting, try both and see which one you like), and unlocking the mouse again when the mouse button is released.

Ask away if you’d like help with any of those, specifically

1 Like

Ahhhhh gotcha, I never thought about rotating the camera haha, I’ll mess around with the info you’ve provided. Thank you, I’ll be sure to ask here if i’ve got any questions!

Okay i’m a little stuck here…

This is what I have so far:

	local model = script.Parent.Parent.ViewportFrame.WorldModel:FindFirstChild("Render")
	if model then
		if HoldInDisplay == false then return end

		if currentX then model.HumanoidRootPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X-currentX)*0.02),0) end

		currentX = X
		currentY = Y

I can’t get the model to move in the Y direction very well, I tried replacing the X axis, and that didnt feel very good to control. Thanks again!

EDIT: There’s more to this, this is just the rotate section.

1 Like

Hah, I found an old post where I posted my own code for this. I thought it was lost to time xD

I don’t know if it even works any more, but feel free to use it directly or take inspiration from it. And ask away if some of the code is unclear, I should be able to decipher my old smelly code.

1 Like

You can try adding the camera position + the position of the mouse (convert it to a vector3 first


  • mouse position = 136, 47;
  • camera position = 0, 0, 0

136, 47 to vector3 must be the vector2 with a Z value of 0 like 136, 47, 0
0, 0, 0 + 136, 47, 0 = 136, 47, 0

therefore the result is 136, 47, 0)

Then you can set the model’s cframe to CFrame.lookAt( whatever position the model had, Vector3.new(136, 47, 0)

1 Like

Oh wow awesome! Thank you so much, I tweeked it a little, and this works perfectly!

1 Like

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