How would i get the players vr height

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    To get the players height in studs so that i can offset their head from a locomotion part.

  2. What is the issue? Include screenshots / videos if possible!
    I cannot get the players height without having to use things like putting a controller on the floor and getting the distance between the controller and the head.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked all over the dev hub.

2 Likes

Boosting because its been 2 hours.

You could make a part with Y being the size of the head and then somehow find the distance between the head and the ground and then scale the Y of the part to head’s Y + the Y value between and then the Y would be the size

I hope this is understandable

I can’t lie this didn’t help me at all. Also if I did it this day it wouldn’t work because there’s no way to offset the VRHead from a Vector3.new(0,0,0) and still have it work because the player head would actually go to Vector3.new(0,0,0) instead of offsetting from it from the players height.

Are you trying to see the height difference from the head to a platform/object below?
If so you can just try projecting a raycast from the head to below and using that to find the height.

If not, can you specify exactly what height you’re talking about? (Show an example image or something, it might help)

I’m trying to get the player’s real-world height for a VR game as I said in the post.


An image explaining my problem, and if you are small enough you can go through the in-game floor.

I don’t think this could be possible but force the player to touch the floor probably

I dont have the VR to test this

local UserInputService = game:GetService("UserInputService")

local function GetLowestPoint()
	local HeadPosition = UserInputService:GetUserCFrame(Enum.UserCFrame.Head).Position
	local FloorPos = HeadPosition.Y
	local Time = 0

	print("you have 10 seconds to touch the floor now")

	while Time <= 10 and task.wait(0.1) do
		print("you have " .. Time .. " seconds to touch the floor now")
		Time += 0.1

		local RightHand = UserInputService:GetUserCFrame(Enum.UserCFrame.RightHand).Position.Y
		local LeftHand = UserInputService:GetUserCFrame(Enum.UserCFrame.LeftHand).Position.Y

		if RightHand < FloorPos then
			FloorPos = RightHand
		end

		if LeftHand < FloorPos then
			FloorPos = LeftHand
		end
	end

	return HeadPosition - FloorPos
end

if UserInputService.VREnabled then
	print(GetLowestPoint())
end

This is what I do already, it’s just that I’ve seen games like opposer make it an automatic thing when joining the game. Also, my system makes the player put the controller on the floor and then lets the user press the trigger on the other controller to confirm their height.

Hello @lrd14

This has been edited and fixed 3/28/2023

In the past I have talked to @GrilledSnakeLegs. The creator of Opposer VR. (He’s also a really nice guy. He usually responds to messages on Discord when he’s not busy.) and he told me something very basic that got my First VR game working. (If you’re reading this Grilled. Thanks!)

Basically your camera is either the middle of your play space (if using Steam, Valve Index, HTC Vive, ETC) or the headsets position on game start (If using an Oculus/Pico/Camera Tracking Headset). This is some incredibly useful information. Attaching your camera to parts is easier when knowing this information.

Getting the height for the player is incredibly simple. Here is a function to do it. Basically create a temporary floor about -4.5 or -5 under the VRCamera (If your not creating your own Camera Instance for VR. Please do. It disables the default VR camera system) then raycast down from the UserCFrame head down to this fake floor.

function GetHeight(FL)
	local FloorLevel = VRCamera.CFrame.Y - FL
	local CalibrationFloor = Instance.new("Part",workspace) --Creating our CalibrationFloor
	CalibrationFloor.Anchored = true
	CalibrationFloor.Name = "CalibrationFloor"
	CalibrationFloor.CanCollide = false
	CalibrationFloor.Size = Vector3.new(1000, 0.001, 1000)
	CalibrationFloor.Material = Enum.Material.ForceField
	CalibrationFloor.Color = Color3.fromRGB(126,0,255)
	CalibrationFloor.CFrame = VRCamera.CFrame * CFrame.new(0,FloorLevel,0)
	
	CalibrationFloor.Transparency = 0 --Change this to a 1 to make this Floor Invisible.
	
	local CalibrationParams = RaycastParams.new()
	CalibrationParams.FilterDescendantsInstances = {CalibrationFloor}
	CalibrationParams.FilterType = Enum.RaycastFilterType.Whitelist
	
	local height = nil
	repeat 
		wait() 
		local cast = workspace:Raycast(game:GetService("VRService"):GetUserCFrame(Enum.UserCFrame.Head).Position,Vector3.new(0,-1,0) * 200,CalibrationParams)
		if cast and cast.Instance and cast.Instance == CalibrationFloor then
			height = cast.Distance
		end
	until height ~= nil
	
	CalibrationFloor:Destroy() --I suggest dashing this out and testing if your controller touching it correctly. You may need to raise the FloorLevel or allow the player to adjust it.
	
	return height
end

warn(GetHeight(4.7))

You may need to do some math with your own height, and the value that was returned. When joining the game stand straight up and look forward

2 Likes

That’s cool, ill try this later as I’m out right now. I didn’t expect to get something like this in the comments but thanks.

It didn’t work for me, it just made the player’s camera be on the floor.

My apologies.

I was kind of in a hurry writing the original. Let me fix it.