Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to move player if the device acceleration is greater than a number?

Asked by
sssynk 58
5 years ago

So I want to user UserInputService to get the device acceleration, then if it is over a certain amount, move the player forward. I used some code from the Roblox Developer Forums and edited it a bit to make this, but it is not working. It is inside of a LocalScript inside of the StarterPlayerScripts folder.

local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local accelerometerEnabled = UserInputService.AccelerometerEnabled
Players = game:GetService("Players")

while true do

if accelerometerEnabled then
    local acceleration = UserInputService:GetDeviceAcceleration().Position
    if acceleration > 10 then
        local direction = camera.CFrame.LookVector
        game.Players.LocalPlayer:Move(Vector3.new(direction), true)
    end
else
    warn("[DeltaVR] User does not have an enabled accelerometer!")
end
wait(0.1)
end

Sorry if my code is messy, or is way off. I am new! Thank you in advance.

  • ItzHiimnew

2 answers

Log in to vote
0
Answered by 5 years ago

Never did anything like this, do some print debugging to find out the actual number that the accelerometer spits out and if it spits out anything, that is.

Ad
Log in to vote
0
Answered by
sssynk 58
5 years ago
Edited 5 years ago

Ok. It appears to spit out X,Y,Z coordinates from what I am seeing. Link below to picture. When I move the device, the numbers grow depending on which way I move the device.

https://prnt.sc/oab64s

Answer this question