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

How would one detect a mid-air anchored part?

Asked by
Marios2 360 Moderation Voter
9 years ago

The IsGrounded function won't work because the part is anchored itself, i have tried everything else and i cannot make this to work. I am not asking for the whole thing, just the basic idea.

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

On a flat plane, disassembling's idea would be the best way.

But if you have multiple levels of terrain, you clearly must do something different.

What I did in a similar situation is use raycasting. Basically, we just raycast straight down. If it hits something, then we know it's on the ground.

function checkPart(part)
    local ray = Ray.new(part.Position, Vector3.new(0, -5, 0))
    local hit, position = workspace:FindPartOnRay(ray)
    if hit then
        return true
    end
end

Of course, the -5 will vary depending on the size of the part you want to check. You could make this automatic with a few edits.

0
Thanks a lot. Marios2 360 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

You can try by detecting wether the part's Y axis is 0 ( I haven't tested this as I am at school ) But an example would be:

local r = Instance.new("Part", game.Workspace)
r.Anchored = true
r.CFrame = CFrame.new(2, 5, 0)
if r.CFrame.y == 0 then
print("it is grounded, and anchored")
elseif r.CFrame.y > 0 or  r.CFrame.y < 0 then
print("It is not grounded, either above 0 or below, and is anchored")
end

wait(5)
r:Destroy()

print("Script should go through.)
0
Although your script only works for one level of terrain and lacks a string ending at last print, you get an upvote for effort. Marios2 360 — 9y
0
Thanks! disassembling 48 — 9y

Answer this question