How to detect a player's height when floating?



  • I want to make a command that, when used, detects how high above the ground I'm floating and then teleports me to the ground.
    But I'm not sure how to detect how high the player is above ground.



  • I tried a few versions and this one seems the best. As datapack called tp and function ground.mcfunction, do:

    ground.mcfunction

    execute align y unless block ~ ~-1 ~ air run tp @s ~ ~ ~
    execute positioned ~ ~-1 ~ if block ~ ~ ~ air run function tp:ground
    

    It basically moves a block down, if it is grounded, tp the player, if not, move one block down and run the function from those coordinates.

    If you want to run the command for a player/entity, just do:

    /execute as [YourTarger] at @s run function tp:ground
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2