What you can do, is raycasting. We first tell the script to create an ray, 5 studs in front of the HumanoidRootPart.LookVector. Then we ray downwards 10 studs, to check if the ray found anything, If it did not find anything, we know there is a “long way down”, hints we’re at a edge of a building for example.
local RayStart = HumanoidCFrame.Position + HumanoidCFrame.LookVector*5 -- 5 studs ahead of player
local RayDirection = RayStart + Vector3.new(0,-1,0) -- We just tell the ray to go straight down
local RayResult = workspace:Raycast(RayStart, RayDirection * 10) -- We ray 10 studs downwards
if not RayResult then
-- If no ray result, we know they're on a edge.
end
Yup, but that raycast when should happen? on a loop? when player is jumping? I think having a touching part at the edges as @bura1414 suggested is a good idea
how can i check if the player is on the edge of an building “a part”?
im trying to make a system to give you an speed boost when you jump off from a build by the edge and i have no idea of how to do it, can someone help me?
“im trying to make a system to give you an speed boost when you jump off from a build by the edge and i have no idea of how to do it, can someone help me?”
There is no need to cast a ton of rays. Personally I don’t see that it’s worth having the feature, that they get speed boost while jumping sideways or backwards.
its boosting without being at edge whats happening?
hum.Jumping:connect(function()
local RayStart = hrp.Position + hrp.CFrame.LookVector *5-- 5 studs ahead of player
local RayDirection = RayStart + Vector3.new(0,-1,0) -- We just tell the ray to go straight down
local RayResult = workspace:Raycast(RayStart, RayDirection * 10) -- We ray 10 studs downwards
if not RayResult and hum.FloorMaterial ~= Enum.Material.Air then
local Vel = Instance.new("BodyVelocity")
local n = math.random(5,10)
Vel.Parent = hrp
Vel.Velocity = Vector3.new(0,0,0)
Vel.MaxForce = Vector3.new(1,1,1) * math.huge
Vel.Velocity = hrp.CFrame.LookVector * 50 + Vector3.new(0,10,0)
print("bost")
game.Debris:AddItem(Vel, .15)
end
end)
Here you go, the issue was that RayDirection bugged. Instead we just get the upvector, and goes into the negative by 1.
local RayStart = hrp.Position + hrp.CFrame.LookVector * 5-- 5 studs ahead of player
local RayDirection = -hrp.CFrame.UpVector*1 -- We just tell the ray to go straight down
local RayResult = workspace:Raycast(RayStart, RayDirection * 10) -- We ray 10 studs downwards
print(RayResult)
if not RayResult and hum.FloorMaterial ~= Enum.Material.Air then
local Vel = Instance.new("BodyVelocity")
local n = math.random(5,10)
Vel.Parent = hrp
Vel.Velocity = Vector3.new(0,0,0)
Vel.MaxForce = Vector3.new(1,1,1) * math.huge
Vel.Velocity = hrp.CFrame.LookVector * 50 + Vector3.new(0,10,0)
print("bost")
game.Debris:AddItem(Vel, .15)
end
end