#get falldistance
1 messages · Page 1 of 1 (latest)
isn't there Player.fallDistance?
Use Entity.isFalling to check if they're falling, each tick.
Initially, false would save their current Y position. After transitioning from true back to false, subtract the old Y position with the current one, which returns the fall distance.
I can't find it on the docs
fallDistance got removed
what? whyy ðŸ˜
idk
anyone?
Dude, can't you replicate this with your own? Or someone needs to make one for you?
im so confused on what ur saying there
function getFallDistanceAsync(player: Player) {
return new Promise(async (resolve) => {
if (!player.isFalling) {
resolve(0)
return
}
const startY = player.location.y
while (player.isFalling) {
await system.waitTicks(2)
}
resolve(startY - player.location.y)
})
}```
```ts
async function playerTracker(player: Player) {
player.sendMessage("Starting fall tracker for the player")
const fallDistance = await getFallDistanceAsync(player)
player.sendMessage(`I fell ${fallDistance} blocks!`)
}```
const yChange = {};
const startingYCoord = {};
system.runInterval(()=>{
world.getPlayers().forEach((player)=>{
const currY = player.location.y;
const onGround = player.isOnGround;
const moveUpwards = player.getVelocity().y>=0;
if (!moveUpwards)
delete yChange[player.id]
if (onGround || moveUpwards) {
const oldY = startingYCoord[player.id] ?? currY;
if (oldY-currY>0 && !yChange[player.id] && !player.isFlying) {
breakFallEvent(player,oldY-currY);
yChange[player.id] = true;
}
startingYCoord[player.id] = currY;
}
})
})
function breakFallEvent(player,fallDistance) {
player.onScreenDisplay.setActionBar("FallDistance: §e"+fallDistance)
}
This version takes into account that if the player stops falling, or possibly levitates upwards mid-air... then, it resets the Y starting point.
Whattttt??