Essentially, what I’m doing in this block of code is getting the position of controllers in VR, and using AlignPosition and AlignOrientation constraints to move the player’s arm to the position of a controller.
However, when I playtest, the arm appears to move to the controller’s position momentarily, and then drops out of the air for no apparent reason to me.
leftHand and Righthand both refer to groups which are pivoted to the position of the controllers constantly. These work consistently without error.
Apologies if the code is messy or confusing. I have never been great at making code readable.
workspace.CurrentCamera.HeadScale = 1
local leftHand = script.Parent:WaitForChild("Left Hand Indicator")
leftHand.Parent = workspace
local rightHand = script.Parent:WaitForChild("Right Hand Indicator")
rightHand.Parent = workspace
local leftAlign1 = Instance.new("AlignPosition")
local leftAlign2 = Instance.new("AlignOrientation")
local leftattachment = Instance.new("Attachment")
local leftArm = game.Players.LocalPlayer.Character:WaitForChild("Left Arm")
leftArm:BreakJoints()
leftArm.Massless = true
leftattachment.Parent = leftArm
leftAlign1.Parent = leftattachment
leftAlign1.Mode = Enum.PositionAlignmentMode.OneAttachment
leftAlign1.RigidityEnabled = true
leftAlign1.ApplyAtCenterOfMass = true
leftAlign1.Position = leftArm.Position
leftAlign1.Attachment0 = leftattachment
leftAlign2.Parent = leftattachment
leftAlign2.Mode = Enum.OrientationAlignmentMode.OneAttachment
leftAlign2.RigidityEnabled = true
leftAlign2.Attachment0 = leftattachment
local function align()
local headcframe = game.VRService:GetUserCFrame(Enum.UserCFrame.Head)
local lefthandcframe = game.VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
local righthandcframe = game.VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
if headcframe and lefthandcframe and righthandcframe then
lefthandcframe = (workspace.CurrentCamera.CFrame*CFrame.new(lefthandcframe.p*workspace.CurrentCamera.HeadScale))*CFrame.fromEulerAnglesXYZ(lefthandcframe:ToEulerAnglesXYZ())
righthandcframe = (workspace.CurrentCamera.CFrame*CFrame.new(righthandcframe.p*workspace.CurrentCamera.HeadScale))*CFrame.fromEulerAnglesXYZ(righthandcframe:ToEulerAnglesXYZ())
leftHand:PivotTo(lefthandcframe)
rightHand:PivotTo(righthandcframe)
leftAlign1.Position = leftHand.PrimaryPart.CFrame.Position
leftAlign2.PrimaryAxis = leftHand.PrimaryPart.CFrame.UpVector
leftAlign2.SecondaryAxis = leftHand.PrimaryPart.CFrame.LookVector*-1
end
end
if game.VRService.VREnabled then
game["Run Service"]:BindToRenderStep("Align",Enum.RenderPriority.Character.Value+1,align)
end