How to make a user input compass?

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

Any scripts will help!

1 Like

Everyone knows what compass is but I assume that nobody knows what you want. Please be more specific.

2 Likes

So I want the compass move, by moving the device, like using some gyroscope or accelorator or something :face_with_raised_eyebrow:

Please just give us the problem and people can help you.

1 Like

I’d just use the humanoid’s “MoveDirection” property and position the compass’s needle accordingly.

Here you will find all the information about getting the input from gyroscope (code examples included): UserInputService.GyroscopeEnabled

I want the property Rotation set to what it should be, to make it look like it’s working.

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.

1 Like

The script I had before is:

2 Likes

Well, not the full script, something like:

script.Parent.Background.Arrow.Rotation = 0 -- something
1 Like

couldn’t you just use the inverse of the humanoidrootpart’s LookVector for this

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.

Second thoughts:

math.atan2 takes the Y arguement first not the X arguement. Not sure if that’s an issue.

Like this?

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