I’m basically trying to make a custom character, and I’m trying to expand to mobile users as well.
However, the script I currently have just doesn’t seem to work at all. It feels very unresponsive and buggy. I simply want the custom character to go in the direction the thumbstick is.
Example Video:
You can try it here on a mobile device.
https://www.roblox.com/games/5296406858/Playable-Rock
Script:
function checknan(xnum)
local val = 0/0
if xnum ~= val then
return true
else
return false
end
end
function GetInputDirection()
local Controller = require(player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
local MovementVector = Controller:GetMoveVector()
local CameraLook = workspace.CurrentCamera.CFrame.LookVector
local Offset = CFrame.new(Vector3.new(),Vector3.new(CameraLook.x,0,CameraLook.z))*MovementVector
local InputDirection = Offset.unit
return InputDirection
end
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled
and not UserInputService.GamepadEnabled and not GuiService:IsTenFootInterface() then
--mobile player
while true do
local acc = char.Force.Value --desired acceleration
local hrp = char:WaitForChild("HumanoidRootPart")
hrp.BodyForce.Force = (GetInputDirection() - hrp.Position).Unit * hrp:GetMass() * acc
hrp.BodyForce.Force = Vector3.new(hrp.BodyForce.Force.X, 0, hrp.BodyForce.Force.Z)
print(checknan(hrp.BodyForce.Force.X))
if checknan(hrp.BodyForce.Force.X) == true then
hrp.BodyForce.Force = Vector3.new(0, 0, 0)
end
print(hrp.BodyForce.Force)
RunService.Stepped:Wait()
end
How can I fix this?
No errors, local script in StarterCharacterScripts
Here is the composition of the custom character if needed

I would really appreciate a fix asap because I am hoping to allow my friends to come to join my game (Who don’t have access to a PC).