AlignPosition letting parts fall out of air

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
1 Like

The reason is because the client is for some reason loosing Network Ownership.

My suggestion is to use SetNetworkOwner on the Server to ensure that the Player does not loose this control.

1.The server supplies the Players with the Hands and Head unless it is a custom character. If it is a custom character it isn’t required.
2.Detect when the character is added and use SetNetworkOwner on the Part that the AlignPosition and AlignOrientation is put in.
3.Then use the client to move the VR stuff around. For a basic anti-cheat I suggest teleporting the Hand near the character via server when it’s too far away.

(Network Ownership also allows the client to manipulate the Physics object on the server. So everyone can see it)

1 Like