#distance between entity and ground
1 messages · Page 1 of 1 (latest)
you mean ground like the first block under entity or ground like a specified y level?
The first block under entity
import {world, system} from '@minecraft/server'
function entityHeight(dimension) {
for (let e of world.getDimension(dimension).getEntities()) {
if (e != undefined) {
const eloc = e.location
let currentBlock = world.getDimension(dimension).getBlock(eloc)
for (let i = 0; i < 320; i++) {
let nextBlock = currentBlock.below(1)
if (nextBlock.isAir == false) {
world.sendMessage(`${i} ${e.typeId}`)
break;
} else {
currentBlock = nextBlock
}
}
}
}
}
const dimensions = [
"nether", "overworld", "the_end"
]
system.runInterval(()=> dimensions.forEach(dimension => {entityHeight(dimension); }),10)
it gets all entities id and their height from ground works in all dimensions
this function only gets int numbers for height if you want it to be also for decimals you have to use y instead of block.below(1)
Thank u so much 🙏
np
hey, new scripter here - how can I use this to set an entity's property? I've been trying to make a script that detects an entity's distance from the ground and setting an entity property to that value
dynamic property?
basically its an entity property that is stored in an entity and the value is it's distance from the ground
entity.setProperty("property:example", <value>)