export function snapRotation(entity, interval = 90) {
    const rotation = entity.getRotation()
    const snappedRotation = Math.round(rotation.y / interval)

    entity.setRotation(
        {
            x: rotation.x,
            y: snappedRotation * interval
        }
    )
}

export function getDistance(entity1, entity2) {
    const x1 = entity1.location.x
    const y1 = entity1.location.y
    const z1 = entity1.location.z

    const x2 = entity2.location.x
    const y2 = entity2.location.y
    const z2 = entity2.location.z

    const powx = Math.pow(x1 - x2, 2)
    const powy = Math.pow(y1 - y2, 2)
    const powz = Math.pow(z1 - z2, 2)

    return Math.sqrt(powx + powy + powz)
}