How can you detect if a player is falling?
I want to make a parkour map and when players fall they will be teleported back to the beginning of the parkour.
Is there a command or a set of commands to detect whether or not a player is falling?
This is actually not too difficult to implement by using scoreboard magic.
First, set up some scoreboard commands
scoreboard objectives add airborne dummy
scoreboard objectives add fallen dummy
Next, run the following commands on a fast clock (I suggest using a fill clock), in this order.
scoreboard players set @a airborne 0
execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:air -1 scoreboard players set @p airborne 1
scoreboard players set @a[score_airborne=0] fallen 0
scoreboard players add @a[score_airborne_min=1] fallen 1
The first two will set airborne
to 1 for every player who is not standing on something, i.e. the block beneath him is air
. The third command will reset the fallen
score to 0 for everyone who is not airborne
, the fourth increments the score 20 times a second instead. This means that fallen
is 0 as long as you were standing on something since your last fall.
Now you can select the falling players for teleportation using @a[score_fallen_min=XYZ]
. Replace XYZ
with however many seconds a player has to be above air to be considered "falling", multiplied by 20.
There is an issue with this however: Standing on the edge of a block will make you be considered falling, and I can't think of an elegant solution to this, short of chaining execute detect
commands to check a 3×3 area below the player for blocks.
You don't need redstone to accomplish what you are describing here. Either make the floor lava, or void, or something like that, and have the player spawn back at the beginning.
You can do it with redstone, but just having the player die upon falling off is just as effective.
/tp @a[x=#,y=#,z=#,r=#] X Y Z
This will teleport all players in a radius centered at an XYZ to the second XYZ. Make sure that the r (Radius of area in which players will be affected) is large enough to cover the entire bottom of your parkour, so that way it will teleport the player from the specified radius to the XYZ coordinates you put in. Loop it on a fill clock or set it to always active if you are in 1.9. however, you may want to create several areas that will teleport players if you are planning on checkpoints.