Im using a raycast that starts at the players root part. But I’ve researched on the dev forum and can’t find how I would get the distance between the ground and the player.
game:GetService("RunService").Heartbeat:Connect(function()
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude; raycastParams.FilterDescendantsInstances = {char}; raycastParams.IgnoreWater = true
local ray = Ray.new(root.CFrame.UpVector, Vector3.new(0, -10, 0))
-- Im looking for something similar to below
if ray.Distance == 10 then
-- DO CODE
end
end)
Yes, I had realized that in the documentation and i’ve changed it to.
local function castRay()
-- The origin point of the ray
local originPosition = root.Position
-- The direction the ray is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the ray
local distance = 10
-- Cast the ray and create a visualization of it
local raycastResult = game.Workspace:Raycast(originPosition, direction * distance)
if not raycastResult then
local velocity = Instance.new("LinearVelocity", char:WaitForChild("HumanoidRootPart"))
local Attachment = Instance.new("Attachment", char:FindFirstChild("HumanoidRootPart"))
Attachment.Name = "glideAttatch"
velocity.Name = "glideVelocity"
velocity.MaxForce = math.huge
velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
velocity.Attachment0 = Attachment
velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
Attachment.WorldPosition = char:FindFirstChild("HumanoidRootPart").AssemblyCenterOfMass
velocity.VectorVelocity = Vector3.new(0,-5,-25)
else
local glideAttach = root:FindFirstChild("glideAttach")
local glideVelocity = root:FindFirstChild("glideVelocity")
if glideAttach or glideVelocity then
glideAttach:Destroy()
glideVelocity:Destroy()
end
end
end
game:GetService("RunService").Heartbeat:Connect(function()
castRay()
end)