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

How would i find if someone is in the air or on the ground?

Asked by 9 years ago

I made a script to make a shockwave when the boss lands after jumping. The thing is, how would I tell if he's back on the ground? (No OnTouched the boss will be on multiple bricks and I don't want to much lag)

1 answer

Log in to vote
0
Answered by 9 years ago

Well, if you have parts on your boss, then you can use Position and an if statement. For example,

OnGround = false -- Assuming the boss starts on the ground
BossTorso = workspace.(Boss model).(Boss's chest) 
--Replace those with the bosses chest, and where it says (Boss model) is what the boss's torso is stored under. If it's not workspace, change it to the location of the boss
DesiredHeight = --(Whatever the grounds y is to find it, click on the ground and look under "Position" and "Y") --This is where he has to be to be "on the ground"
BossHeight = --(You can experiment here but I'd probably recommend 7, or so depending on how tall your boss is) --This is subtracted from the value because you're measuring the torso
while 1==1 do --Repeats 4ever
if BossTorso.Position.y <= DesiredHeight + BossHeight then --Checks if the bosses torso 5 studs away from the ground
    OnGround = true 
    break--breaks loop remove this if you want it to go on forever.
    end
wait(1)
end

I told you want to replace in the comments of the script, try using that reply if that doesn't make sense. Use OnGround in a loop, to see if he hits the ground, for example,

while 2==2 do
if OnGround = true
        --Do whatever you're shockwave thing is
    end
wait(1)
end

If I were to have a brick in workspace, called "Torso", then this script will work for it.

OnGround = false
BossTorso = workspace.Torso 
DesiredHeight = -10
BossHeight = 3
while 1==1 do
if BossTorso.Position.y <= DesiredHeight + BossHeight then
    OnGround = true 
    break
    end
wait(1)
end
while 1==1 do
    if OnGround==true then
        print("Yo")
        break
    end
    wait(1)
end

Assuming that your baseplate is really thin, if it's thick, change the BossHeight to something like 10 or 20. This prints "Yo" Whenever it touches the ground.

0
EDITED DO NOT USE THE OLD ONE, WILL CRASH YOUR GAME feeliirie 5 — 9y
0
Another edit, added working code, finally XD feeliirie 5 — 9y
Ad

Answer this question