Mobile "VR" Camera Lock

I’ve created a mobile button that’s capable of toggling between a first person view similar to VR and the default camera. It uses your mobile device’s gyroscope + accelerometer to fluidly change your camera’s CFrame.

The main benefit of this mobile camera controller is that it supports both portrait and landscape mode.

Poor video representation (since I didn’t have any external cameras at my disposal, to record myself interacting with the mobile device) :point_down:

This code was made to improve mobile UX - This should prove to be a more ergonomic replacement for the default first person camera on mobile.

Uncopylocked demonstration place :point_down:

𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻

PlayerGui.CurrentScreenOrientation does not return whether a player is in portrait or any type of landscape mode when the screenorientation is set to Sensor - which means you’ll have to figure that out with some other code (which is provided in my place)

Related Developer hub pages

https://developer.roblox.com/en-us/articles/Understanding-CFrame

https://developer.roblox.com/en-us/api-reference/property/UserInputService/GyroscopeEnabled

https://developer.roblox.com/en-us/api-reference/function/UserInputService/GetDeviceRotation

https://developer.roblox.com/en-us/api-reference/function/UserInputService/GetDeviceGravity

https://developer.roblox.com/en-us/api-reference/enum/ScreenOrientation

https://developer.roblox.com/en-us/api-reference/property/UserInputService/AccelerometerEnabled

https://www.roblox.com/games/257877593/Accel-Test

I’ve left all my comments inside the code as to show some of the pitfalls I’ve dealt with. There is also a disabled screenGUI inside the place which can be used for debugging.

35 Likes

This was really awesome! I was surprised by how well it worked!
Amazing job!
On my iPhone 7, In portrait mode, I would have to flip my phone upside down otherwise it would be inverted, (Probably just me) But both ways worked really well in landscape.

6 Likes

Woah… This works great on the pixel 4. Glad I saw this, might try making a game using this, thank you so much!

2 Likes

Looks really awesome! I may use this for a future project of mine

I’ve been looking for something like this for MONTHS! Thank you so much!

This is officially my favorite post. This will help so much in exploration type games