I have a script to clone the local player’s model in a viewport frame so they can test out emotes, poses etc.
The model can be rotated around with mouse.
How can I limit this rotation to seperate angles? I want, for example 90 degrees left and right, no more than that.
full code here
-- Variables
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local resetRotationButton = script.Parent.ResetRotation
local hoverSound = game.Workspace.HoverSound
local clickSound = game.Workspace.ClickSound
local MouseInDisplay, HoldInDisplay = false, false
local currentX
-- Character Display
local VPFcam = Instance.new("Camera"); VPFcam.Parent = script.Parent.ViewportFrame
VPFcam.CFrame = CFrame.new(0,0,0)
script.Parent.ViewportFrame.CurrentCamera = VPFcam
repeat wait(.1) until game:IsLoaded()
char.Archivable = true
local ClonedChar = char:Clone()
ClonedChar.Parent = script.Parent.ViewportFrame.WorldModel
ClonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedChar.Name = "Model"
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5),Vector3.new(0,0,0)))
-- Turning Feature
uis.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if MouseInDisplay == true then
HoldInDisplay = true
currentX = nil
end
end
end)
uis.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
HoldInDisplay = false
end
end)
script.Parent.ViewportFrame.MouseMoved:Connect(function(X,Y)
if HoldInDisplay == false then return end
if currentX then ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X-currentX)*.01),0) end
currentX = X
end)
script.Parent.ViewportFrame.MouseEnter:Connect(function() MouseInDisplay = true end)
script.Parent.ViewportFrame.MouseLeave:Connect(function() MouseInDisplay = false end)
resetRotationButton.MouseButton1Click:Connect(function()
ClonedChar.PrimaryPart.Orientation = Vector3.new(0,0,0)
clickSound:Play()
end)
resetRotationButton.MouseEnter:Connect(function()
hoverSound:Play()
end)