Unioin Rotation inside viewport frame not following mouse properly

https://i.gyazo.com/6c65fcbf72c8cb602d311c44880ff8e2.mp4

Im trying to make it go to the mouse but i cannot get it to work!

local ViewportFrame = script.Parent.Frame.ViewportFrame
local Part = ViewportFrame.WorldModel.Union


local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = game.Workspace.CurrentCamera

local PivotOffset = Vector3.new(0.81, 0.255, 0)
local Pivot = CFrame.new(Part.Position) * CFrame.new(PivotOffset) * Part.CFrame

local function rot()

		local axis = Vector3.new(0, Mouse.Hit.y, 0)
	local rotation = CFrame.fromAxisAngle(axis, math.rad(5))

		
	Part.CFrame = Part.CFrame * CFrame.new(PivotOffset) * rotation * CFrame.new(-PivotOffset)
	
	
	end

Mouse.Move:Connect(rot)

1 Like

Hay, I had a similar problem a few months ago.

Try this:

local ViewportFrame = script.Parent.Frame.ViewportFrame
local Part = ViewportFrame.WorldModel.Union

local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = game.Workspace.CurrentCamera

local PivotOffset = Vector3.new(0, 0, 0)
local Pivot = CFrame.new(Part.Position) * CFrame.new(PivotOffset) * Part.CFrame

local function rot()
	local axis = Vector3.new(0, Mouse.Hit.y, 0)
	local rotation = CFrame.fromAxisAngle(axis, math.rad(5))

	Part.CFrame = Part.CFrame * CFrame.new(PivotOffset) * rotation * CFrame.new(-PivotOffset)
end

Mouse.Move:Connect(rot)

It’s the same result but it is not moving with the pivot. https://i.gyazo.com/13e7cd00a80eb689647ad09e0d8ca8a2.mp4