How to make a compass through GUI?
I don’t want to make the compass move in the game world, I want it moving using UserInputService
If you want to know what compass is:
The problem was that arrow wasn’t moving correctly:
local Service = game:GetService('UserInputService')
local Run = game:GetService('RunService')
game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
if Service.GyroscopeEnabled then
Service.DeviceRotationChanged:Connect(function(input, cframe)
local lookVector = cframe.LookVector
script.Parent.Background.Arrow.Rotation = math.deg(math.atan2(lookVector.X, lookVector.Z))
end)
else
Instance.new('ColorCorrectionEffect', workspace.CurrentCamera).TintColor = Color3.new(0, 0, 0)
end
if Service.VREnabled then
spawn(function()
while true do
Run.Stepped:Wait()
local cframe = Service:GetUserCFrame(Enum.UserCFrame.RightHand)
local lookVector = cframe.LookVector
script.Parent.Background.Arrow.Rotation = math.deg(math.atan2(lookVector.X, lookVector.Z))
end
end)
else
Instance.new('ColorCorrectionEffect', workspace.CurrentCamera).TintColor = Color3.new(0, 0, 0)
end
Everything is in the wiki article that I linked in my previous reply. Here on devforum we give advice, not create scripts for you. All you need is explained very well on Roblox Wiki.
I looked at your script and my first thought is you should take the XZ values of the LookVector of where the “compass” is facing and dot it with the North vector (Vector3.new(0,0,-1) i think). And then a value of 1 is facing north, a value of 0 is facing either east or west, and -1 is South. You could also compare the RightVector with the East vector (Vector3.new(1,0,0) i believe).
Edit:
The Dot product of two Unit vectors will give you a value between -1 and 1 (-1 <= X <= 1). And then 0 means they are orthogonal or at a 90 degree angle between each other.
local Service = game:GetService('UserInputService')
local Run = game:GetService('RunService')
local lastInputFrame = nil
game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
if Service.GyroscopeEnabled then
Service.DeviceRotationChanged:Connect(function(input, cframe)
local lookVector = cframe.LookVector
script.Parent.Background.Arrow.Rotation = lookVector:Dot(Vector3.new(0, 0, -1))+50
end)
else
Instance.new('ColorCorrectionEffect', workspace.CurrentCamera).TintColor = Color3.new(0, 0, 0)
end