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.
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.
1 | function checkPart(part) |
2 | local ray = Ray.new(part.Position, Vector 3. new( 0 , - 5 , 0 )) |
3 | local hit, position = workspace:FindPartOnRay(ray) |
4 | if hit then |
5 | return true |
6 | end |
7 | 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.
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:
01 | local r = Instance.new( "Part" , game.Workspace) |
02 | r.Anchored = true |
03 | r.CFrame = CFrame.new( 2 , 5 , 0 ) |
04 | if r.CFrame.y = = 0 then |
05 | print ( "it is grounded, and anchored" ) |
06 | elseif r.CFrame.y > 0 or r.CFrame.y < 0 then |
07 | print ( "It is not grounded, either above 0 or below, and is anchored" ) |
08 | end |
09 |
10 | wait( 5 ) |
11 | r:Destroy() |
12 |
13 | print ("Script should go through.) |