Is it possible to make a phone face depending on your phone?

Over the last few months, I found an app which I forget where you can see the skies and the stars on your phone and you can do that by rotating it. It’s kind of like VR but you don’t wear it and you only just hold your phone. (Example if you face your phone up, the camera in game will face up. If your phone is facing to the left, the camera in game will face to the left.

Is it possible to achieve this and how?

The wiki page has an example code of exactly what you want to do.

1 Like

I went to the website and used that script but it keeps sending errors that says

  • vector3 expected, got nil
  • cframe expected, got nil

I don’t know if i’m doing right.

Seeing a sample of your code will help solve these issues.

In relation to the error, do exactly what it says.

Change x to Vector3.new()
Change x to CFrame.new()

1 Like
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local character = script.Parent
local head = character:WaitForChild("Head")
local lastInputFrame
local currentRotation = 0


local function GravityChanged(gravity)
    if not orientationSet then
   	 upsideDown = (gravity.Position.X < -.5 or gravity.Position.Z > .5)
 
   	 orientationSet = true
    end
end
 
local function RotationChanged(rotation, rotCFrame)
	if orientationSet then
	if not lastInputFrame then
		lastInputFrame = rotCFrame
	end
 
	local delta = rotCFrame * lastInputFrame:inverse()
	local x,y,z = delta:toEulerAnglesXYZ()
	if upsideDown then
		delta = CFrame.Angles(-x, y, z)
	else
		delta = CFrame.Angles(x, -y, z)
	end
	currentRotation = currentRotation * delta
 
	lastInputFrame = rotCFrame
	end
end
 
local function HideCharacter()
	for _, limb in pairs (character:GetChildren()) do
		if limb:IsA("Part") then
			limb.Transparency = 1
		end
	end
end
 
local function UpdateCamera()
	local camera = game.Workspace.CurrentCamera
	camera.CoordinateFrame = currentRotation
	camera.Focus = CFrame.new(currentRotation * Vector3.new(0,0,-10))
end
 
if UserInputService.GyroscopeEnabled then
	UserInputService.DeviceGravityChanged:Connect(GravityChanged)
	UserInputService.DeviceRotationChanged:Connect(RotationChanged)
	
	HideCharacter()
	
	RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, function()
		camera.CFrame = CFrame.new(head.Position - Vector3.new(0,8,10)) * currentRotation
		camera.Focus = CFrame.new(currentRotation * Vector3.new(0,0,-10))
	end)
end


local gyroIsEnabled = UserInputService.GyroscopeEnabled
if (gyroIsEnabled) then
	print("Gyroscope is enabled!")
else
	print("Gyroscope is not enabled!")
end

RunService.RenderStepped:Connect(function(dt)
	UpdateCamera()
end)

New to this so idk how it works and how to set up.

What lines do the errors trace back to?

actually i’ll just screenshot it hold on.

You never defined orientationSet

1 Like

Ok I set it to false as default, but still it’s not working (obviously)

I still need help and I’ve been trying to figure out what’s the error so I’ll be glad if someone can help me.