Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Detecting if a player is "outside"?

Asked by
gitrog 326 Moderation Voter
6 years ago

Not quite sure where to start here. I want to check if a player is outside, meaning there are no blocks above them. Any ideas or solutions on where to start? I just need this part, I can do the rest of the blizzard script.

1 answer

Log in to vote
1
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

You could use a ray to find out if there's a part immediately above the character's head. In a nutshell, a ray is a line that is finite in one direction and infinite in the other.

function isInside (char)
    local head = char:WaitForChild("Head")
    local ray = Ray.new(head.Position , Vector3.new(0 , 1 , 0) * 999)
    if workspace:FindPartOnRay(ray , char) then return true end
    return false
end

Basically, the idea is to make a ray that starts at the head's position and goes upwards. If the ray intersects with a part then the player is indoors. We also need to pass in the character instance as a parameter to tell that the ray should ignore any descendants of the character model.

0
Actually, problem popped up with this. gitrog 326 — 6y
0
The ray you create always points South. How would I make it point straight upwards? gitrog 326 — 6y
0
Fixed! RayCurse 1518 — 6y
0
You accepted answer after one year. Noice RayCurse 1518 — 5y
Ad

Answer this question