#VR with visible body

1 messages · Page 1 of 1 (latest)

tidal plover
#

Hi! Im trying to make so a vr player can see their arms and the arms and hands follow the players controller position. I tried doing it on my own but it doesnt work

jaunty fable
#

can u show the code?

jaunty fable
#

@tidal plover

tidal plover
#

Here is the First one (VR.IK)

#

local VRService = game:GetService("VRService")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local remote = game.ReplicatedStorage:WaitForChild("VRUpdate")
local rotationFix = CFrame.Angles(math.rad(90), 0, 0)
root.Anchored = true

-- 🔁 FUNKAR EFTER RESPAWN
local function setupCharacter(character)

local humanoid = character:WaitForChild("Humanoid")
local head = character:WaitForChild("Head")
local root = character:WaitForChild("HumanoidRootPart")
local rightHand = character:WaitForChild("RightHand")
local leftHand = character:WaitForChild("LeftHand")

-- ⚠️ GÖM EGET HUVUD
for _, v in ipairs(character:GetDescendants()) do
    if v:IsA("BasePart") then
        v.LocalTransparencyModifier = 1
    end
end

-- IK
local function createIK(endEffector, chainRoot)
    local ik = Instance.new("IKControl")
    ik.Type = Enum.IKControlType.Transform -- 🔥 FIXAR ROTATION
    ik.EndEffector = endEffector
    ik.ChainRoot = chainRoot
    ik.SmoothTime = 0 -- 🔥 INGEN DELAY
    ik.Weight = 1
    ik.Parent = humanoid
    ik.Priority = Enum.IKControlPriority.Action
    ik.Weight = 1
    return ik
end

local rightIK = createIK(rightHand, character:WaitForChild("RightUpperArm"))
local leftIK = createIK(leftHand, character:WaitForChild("LeftUpperArm"))

-- Targets
local function createTarget()
    local p = Instance.new("Part")
    p.Size = Vector3.new(0.5,0.5,0.5)
    p.Transparency = 1
    p.Anchored = true
    p.CanCollide = false
    p.Parent = workspace
    return p
end

local rightTarget = createTarget()
local leftTarget = createTarget()

rightIK.Target = rightTarget
leftIK.Target = leftTarget
#

-- VR ON
local function enableVR()
local animate = character:FindFirstChild("Animate")
if animate then animate.Disabled = true end

    for _, track in ipairs(humanoid:GetPlayingAnimationTracks()) do
        track:Stop()
    end

    humanoid.AutoRotate = false
    humanoid:ChangeState(Enum.HumanoidStateType.Physics)
end

enableVR()

-- LOOP
local rotationFix = CFrame.Angles(math.rad(90), 0, 0)

RunService.RenderStepped:Connect(function()
    if not VRService.VREnabled then return end

    local headCF = UIS:GetUserCFrame(Enum.UserCFrame.Head)
    local leftCF = UIS:GetUserCFrame(Enum.UserCFrame.LeftHand)
    local rightCF = UIS:GetUserCFrame(Enum.UserCFrame.RightHand)

    local camCF = camera.CFrame

    -- händer (med rotation fix)
    leftTarget.CFrame = camCF * leftCF * rotationFix
    rightTarget.CFrame = camCF * rightCF * rotationFix

    -- huvud
    head.CFrame = camCF * headCF

    -- multiplayer
    remote:FireServer(headCF, leftCF, rightCF)
end)

-- 🔁 FIXAR RESPAWN
if player.Character then
setupCharacter(player.Character)
end

player.CharacterAdded:Connect(setupCharacter)

#

⛔ And then the second one⛔

#

(VR.MULTI)

#

local remote = game.ReplicatedStorage:WaitForChild("VRUpdate")
local camera = workspace.CurrentCamera

remote.OnClientEvent:Connect(function(player, head, left, right)
if player == game.Players.LocalPlayer then return end

local character = player.Character
if not character then return end

local headPart = character:FindFirstChild("Head")
local leftHand = character:FindFirstChild("LeftHand")
local rightHand = character:FindFirstChild("RightHand")

if not (headPart and leftHand and rightHand) then return end

local camCF = camera.CFrame

headPart.CFrame = camCF * head
leftHand.CFrame = camCF * left
rightHand.CFrame = camCF * right

end)

#

⛔ I also have a Remote Event called "VRUpdate" ⛔

#

⛔ And this third script ⛔

#

local remote = game.ReplicatedStorage:WaitForChild("VRUpdate")

remote.OnServerEvent:Connect(function(player, head, left, right)
remote:FireAllClients(player, head, left, right)
end)

#

@jaunty fable

jaunty fable
#

woah thats alot

#

of code

#
local Workspace = game:GetService("Workspace")
local VRService = game:GetService("VRService")

local camera = Workspace.CurrentCamera
local part = script.Parent.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)

-- Account for headscale
handOffset = handOffset.Rotation + handOffset.Position * camera.HeadScale
part.CFrame = camera.CFrame * handOffset
#

this code places a part at users left hand

#

assuming camera.HeadLocked == true

#

start from this example