function MasterControl.GetHumanoid(o)if LocalCharacter then if CachedHumanoid then return CachedHumanoid else CachedHumanoid=LocalCharacter:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")return CachedHumanoid end end end VRService.Changed:connect(function(o)if o=="\086\082\069\110\097\098\108\101\100"then VREnabled=VRService.VREnabled end end)local o=nil local w=nil local function A(A)if o then o:disconnect()end if w then w:disconnect()end LocalCharacter=A CachedHumanoid=LocalCharacter:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")o=A.AncestryChanged:connect(function()if A.Parent==nil then LocalCharacter=nil else LocalCharacter=A end end)w=A.ChildRemoved:connect(function(o)if o==CachedHumanoid then CachedHumanoid=nil end end)end if LocalCharacter then A(LocalCharacter)end LocalPlayer.CharacterAdded:connect(A)local e=MasterControl.GetHumanoid local Q=LocalPlayer.Move local l=VRService.GetUserCFrame local W=function()if not areControlsEnabled then return end local o=e()if not o then return end if isJumpEnabled and(isJumping and not o.PlatformStand)then local w=o:GetState()if w~=STATE_JUMPING and(w~=STATE_FREEFALL and w~=STATE_LANDED)then o.Jump=isJumping end end local w=moveValue if VREnabled and workspace.CurrentCamera.HeadLocked then local o=l(VRService,Enum.UserCFrame.Head)local A=(Vector3.new(o.lookVector.X,0,o.lookVector.Z)).unit local e=CFrame.new(ZERO_VECTOR3,A)w=e:vectorToWorldSpace(w)end Q(LocalPlayer,w,true)end
--
function MasterControl:GetHumanoid()
	if LocalCharacter then
		if CachedHumanoid then
			return CachedHumanoid
		else
			CachedHumanoid = LocalCharacter:FindFirstChildOfClass("Humanoid")
			return CachedHumanoid
		end
	end
end

VRService.Changed:connect(function(prop)
	if prop == "VREnabled" then
		VREnabled = VRService.VREnabled
	end
end)

local characterAncestryChangedConn = nil
local characterChildRemovedConn = nil
local function characterAdded(character)
	if characterAncestryChangedConn then
		characterAncestryChangedConn:disconnect()
	end

	if characterChildRemovedConn then
		characterChildRemovedConn:disconnect()
	end	
	
	LocalCharacter = character
	CachedHumanoid = LocalCharacter:FindFirstChildOfClass("Humanoid")
	characterAncestryChangedConn = character.AncestryChanged:connect(function()
		if character.Parent == nil then
			LocalCharacter = nil
		else
			LocalCharacter = character
		end
	end)
	
	characterChildRemovedConn = character.ChildRemoved:connect(function(child)
		if child == CachedHumanoid then
			CachedHumanoid = nil
		end
	end)
end

if LocalCharacter then
	characterAdded(LocalCharacter)
end
LocalPlayer.CharacterAdded:connect(characterAdded)


local getHumanoid = MasterControl.GetHumanoid
local moveFunc = LocalPlayer.Move
local getUserCFrame = VRService.GetUserCFrame
local updateMovement = function()
	
	if not areControlsEnabled then return end
	
	local humanoid = getHumanoid()
	if not humanoid then return end
	
	if isJumpEnabled and isJumping and not humanoid.PlatformStand then
		local state = humanoid:GetState()
		if state ~= STATE_JUMPING and state ~= STATE_FREEFALL and state ~= STATE_LANDED then
			humanoid.Jump = isJumping
		end
	end
	
	local adjustedMoveValue = moveValue
	if VREnabled and workspace.CurrentCamera.HeadLocked then
		local vrFrame = getUserCFrame(VRService, Enum.UserCFrame.Head)
		local lookVector = Vector3.new(vrFrame.lookVector.X, 0, vrFrame.lookVector.Z).unit
		local rotation = CFrame.new(ZERO_VECTOR3, lookVector)
		adjustedMoveValue = rotation:vectorToWorldSpace(adjustedMoveValue)
	end

	moveFunc(LocalPlayer, adjustedMoveValue, true)
end
